/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-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

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 .lazy_import import lazy_import
 
22
lazy_import(globals(), """
19
23
import stat
 
24
import warnings
20
25
 
21
26
from breezy import (
22
27
    errors,
23
28
    osutils,
24
29
    )
 
30
""")
25
31
 
26
32
# not forksafe - but we dont fork.
27
33
_pid = os.getpid()
28
34
_hostname = None
29
35
 
30
36
 
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
37
class AtomicFile(object):
42
38
    """A file that does an atomic-rename to move into place.
43
39
 
95
91
    def _close_tmpfile(self, func_name):
96
92
        """Close the local temp file in preparation for commit or abort"""
97
93
        if self._fd is None:
98
 
            raise AtomicFileAlreadyClosed(path=self.realfilename,
99
 
                                          function=func_name)
 
94
            raise errors.AtomicFileAlreadyClosed(path=self.realfilename,
 
95
                                                 function=func_name)
100
96
        fd = self._fd
101
97
        self._fd = None
102
98
        os.close(fd)
115
111
        """Discard the file unless already committed."""
116
112
        if self._fd is not None:
117
113
            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()