/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

Merge Jan's benchmarks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2004, 2005 by Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
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)