/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 breezy/atomicfile.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
 
 
21
from .lazy_import import lazy_import
 
22
lazy_import(globals(), """
21
23
import stat
 
24
import warnings
22
25
 
23
26
from breezy import (
24
27
    errors,
25
28
    osutils,
26
29
    )
 
30
""")
27
31
 
28
32
# not forksafe - but we dont fork.
29
33
_pid = os.getpid()
30
34
_hostname = None
31
35
 
32
36
 
33
 
class AtomicFileAlreadyClosed(errors.PathError):
34
 
 
35
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
36
 
            ' "%(path)s"')
37
 
 
38
 
    def __init__(self, path, function):
39
 
        errors.PathError.__init__(self, path=path, extra=None)
40
 
        self.function = function
41
 
 
42
 
 
43
37
class AtomicFile(object):
44
38
    """A file that does an atomic-rename to move into place.
45
39
 
97
91
    def _close_tmpfile(self, func_name):
98
92
        """Close the local temp file in preparation for commit or abort"""
99
93
        if self._fd is None:
100
 
            raise AtomicFileAlreadyClosed(path=self.realfilename,
101
 
                                          function=func_name)
 
94
            raise errors.AtomicFileAlreadyClosed(path=self.realfilename,
 
95
                                                 function=func_name)
102
96
        fd = self._fd
103
97
        self._fd = None
104
98
        os.close(fd)
117
111
        """Discard the file unless already committed."""
118
112
        if self._fd is not None:
119
113
            self.abort()
120
 
 
121
 
    def __enter__(self):
122
 
        return self
123
 
 
124
 
    def __exit__(self, exc_type, exc_val, exc_tb):
125
 
        if exc_type:
126
 
            self.abort()
127
 
            return False
128
 
        self.commit()