~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

  • Committer: John Arbash Meinel
  • Date: 2005-09-15 21:35:53 UTC
  • mfrom: (907.1.57)
  • mto: (1393.2.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050915213552-a6c83a5ef1e20897
(broken) Transport work is merged in. Tests do not pass yet.

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
 
20
 
21
21
 
22
22
class AtomicFile(object):
23
23
    """A file that does an atomic-rename to move into place.
65
65
        self.f.close()
66
66
        self.f = None
67
67
        
68
 
        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)
69
78
 
70
79
 
71
80
    def abort(self):
88
97
 
89
98
 
90
99
    def __del__(self):
91
 
        if hasattr(self, 'closed') and not self.closed:
 
100
        if not self.closed:
92
101
            warn("%r leaked" % self)
93
102