/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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import os
18
20
 
 
21
from bzrlib.lazy_import import lazy_import
 
22
lazy_import(globals(), """
19
23
import stat
 
24
import warnings
20
25
 
21
 
from breezy import (
 
26
from bzrlib import (
22
27
    errors,
23
28
    osutils,
 
29
    symbol_versioning,
24
30
    )
 
31
""")
25
32
 
26
33
# not forksafe - but we dont fork.
27
34
_pid = os.getpid()
28
35
_hostname = None
29
36
 
30
37
 
31
 
class AtomicFileAlreadyClosed(errors.PathError):
32
 
 
33
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
34
 
            ' "%(path)s"')
35
 
 
36
 
    def __init__(self, path, function):
37
 
        errors.PathError.__init__(self, path=path, extra=None)
38
 
        self.function = function
39
 
 
40
 
 
41
38
class AtomicFile(object):
42
39
    """A file that does an atomic-rename to move into place.
43
40
 
71
68
        if new_mode is not None:
72
69
            local_mode = new_mode
73
70
        else:
74
 
            local_mode = 0o666
 
71
            local_mode = 0666
75
72
 
76
73
        # Use a low level fd operation to avoid chmodding later.
77
74
        # This may not succeed, but it should help most of the time
95
92
    def _close_tmpfile(self, func_name):
96
93
        """Close the local temp file in preparation for commit or abort"""
97
94
        if self._fd is None:
98
 
            raise AtomicFileAlreadyClosed(path=self.realfilename,
99
 
                                          function=func_name)
 
95
            raise errors.AtomicFileAlreadyClosed(path=self.realfilename,
 
96
                                                 function=func_name)
100
97
        fd = self._fd
101
98
        self._fd = None
102
99
        os.close(fd)
115
112
        """Discard the file unless already committed."""
116
113
        if self._fd is not None:
117
114
            self.abort()
118
 
 
119
 
    def __enter__(self):
120
 
        return self
121
 
 
122
 
    def __exit__(self, exc_type, exc_val, exc_tb):
123
 
        if exc_type:
124
 
            self.abort()
125
 
            return False
126
 
        self.commit()