~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

  • Committer: Martin Pool
  • Date: 2005-05-16 02:37:37 UTC
  • Revision ID: mbp@sourcefrog.net-20050516023737-efe7091490efdc87
- new AtomicFile.close() aborts if appropriate
- Doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
        self.closed = property(self.f.closed)
47
47
 
48
48
    def commit(self):
 
49
        """Close the file and move to final name."""
49
50
        import sys, os
50
51
        
51
52
        self.f.close()
54
55
        os.rename(self.tmpfilename, self.realfilename)
55
56
 
56
57
    def abort(self):
 
58
        """Discard temporary file without committing changes."""
57
59
        import os
58
60
        self.f.close()
59
61
        os.remove(self.tmpfilename)
 
62
 
 
63
    def close(self):
 
64
        """Discard the file unless already committed."""
 
65
        if not self.closed:
 
66
            self.abort()
60
67
        
61
68