~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-09-04 02:59:56 UTC
  • mfrom: (1172)
  • mto: (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1178.
  • Revision ID: aaron.bentley@utoronto.ca-20050904025956-776ba4f07de97700
Merged mpool's latest changes (~0.0.7)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
 
19
19
from warnings import warn
20
 
from osutils import rename
21
 
import errno
 
20
 
22
21
 
23
22
class AtomicFile(object):
24
23
    """A file that does an atomic-rename to move into place.
66
65
        self.f.close()
67
66
        self.f = None
68
67
        
69
 
        try:
70
 
            stat = os.lstat(self.realfilename)
71
 
            os.chmod(self.tmpfilename, stat.st_mode)
72
 
        except OSError, e:
73
 
            if e.errno != errno.ENOENT:
74
 
                raise
75
 
        rename(self.tmpfilename, self.realfilename)
 
68
        if sys.platform == 'win32':
 
69
            # windows cannot rename over an existing file
 
70
            try:
 
71
                os.remove(self.realfilename)
 
72
            except OSError, e:
 
73
                import errno
 
74
                if e.errno != errno.ENOENT:
 
75
                    raise
 
76
                
 
77
        os.rename(self.tmpfilename, self.realfilename)
76
78
 
77
79
 
78
80
    def abort(self):
95
97
 
96
98
 
97
99
    def __del__(self):
98
 
        if hasattr(self, 'closed') and not self.closed:
 
100
        if not self.closed:
99
101
            warn("%r leaked" % self)
100
102