/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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
18
import os
20
19
 
21
 
from .lazy_import import lazy_import
 
20
from bzrlib.lazy_import import lazy_import
22
21
lazy_import(globals(), """
23
22
import stat
 
23
import socket
24
24
import warnings
25
25
 
26
 
from breezy import (
 
26
from bzrlib import (
27
27
    errors,
28
28
    osutils,
 
29
    symbol_versioning,
29
30
    )
30
31
""")
31
32
 
67
68
        if new_mode is not None:
68
69
            local_mode = new_mode
69
70
        else:
70
 
            local_mode = 0o666
 
71
            local_mode = 0666
71
72
 
72
73
        # Use a low level fd operation to avoid chmodding later.
73
74
        # This may not succeed, but it should help most of the time
78
79
            # the common case is that we won't, though.
79
80
            st = os.fstat(self._fd)
80
81
            if stat.S_IMODE(st.st_mode) != new_mode:
81
 
                osutils.chmod_if_possible(self.tmpfilename, new_mode)
 
82
                os.chmod(self.tmpfilename, new_mode)
 
83
 
 
84
    def _get_closed(self):
 
85
        symbol_versioning.warn('AtomicFile.closed deprecated in bzr 0.10',
 
86
                               DeprecationWarning, stacklevel=2)
 
87
        return self._fd is None
 
88
 
 
89
    closed = property(_get_closed)
82
90
 
83
91
    def __repr__(self):
84
92
        return '%s(%r)' % (self.__class__.__name__,
111
119
        """Discard the file unless already committed."""
112
120
        if self._fd is not None:
113
121
            self.abort()
 
122
 
 
123
    def __del__(self):
 
124
        if self._fd is not None:
 
125
            warnings.warn("%r leaked" % self)