~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-18 02:21:57 UTC
  • mfrom: (1787 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1794.
  • Revision ID: john@arbash-meinel.com-20060618022157-6e33aa9b67c25e4f
[merge] bzr.dev 1787

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
 
import errno
18
 
import os
 
17
 
19
18
 
20
19
from warnings import warn
21
20
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 socket
 
38
        import os, 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
 
 
 
61
        import sys, os
 
62
        
62
63
        if self.closed:
63
64
            raise Exception('%r is already closed' % self)
64
65
 
80
81
 
81
82
    def abort(self):
82
83
        """Discard temporary file without committing changes."""
 
84
        import os
83
85
 
84
86
        if self.closed:
85
87
            raise Exception('%r is already closed' % self)