~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

  • Committer: Robey Pointer
  • Date: 2006-07-01 19:03:33 UTC
  • mfrom: (1829 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1830.
  • Revision ID: robey@lag.net-20060701190333-f58465aec4bd3412
merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
 
 
17
import errno
 
18
import os
18
19
 
19
20
from warnings import warn
20
21
from bzrlib.osutils import rename
21
 
import errno
22
22
 
23
23
class AtomicFile(object):
24
24
    """A file that does an atomic-rename to move into place.
35
35
        if mode != 'wb' and mode != 'wt':
36
36
            raise ValueError("invalid AtomicFile mode %r" % mode)
37
37
 
38
 
        import os, socket
 
38
        import socket
39
39
        self.tmpfilename = '%s.%d.%s.tmp' % (filename, os.getpid(),
40
40
                                             socket.gethostname())
41
41
        self.realfilename = filename
58
58
 
59
59
    def commit(self):
60
60
        """Close the file and move to final name."""
61
 
        import sys, os
62
 
        
 
61
 
63
62
        if self.closed:
64
63
            raise Exception('%r is already closed' % self)
65
64
 
81
80
 
82
81
    def abort(self):
83
82
        """Discard temporary file without committing changes."""
84
 
        import os
85
83
 
86
84
        if self.closed:
87
85
            raise Exception('%r is already closed' % self)