~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

  • Committer: John Arbash Meinel
  • Date: 2005-12-15 20:03:03 UTC
  • mto: (1185.50.20 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1532.
  • Revision ID: john@arbash-meinel.com-20051215200303-be2d09abef0f6e57
Added mode to the appropriate transport functions, and tests to make sure they work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    An encoding can be specified; otherwise the default is ascii.
32
32
    """
33
33
 
34
 
    def __init__(self, filename, mode='wb', encoding=None):
 
34
    def __init__(self, filename, mode='wb', encoding=None, new_mode=None):
35
35
        if mode != 'wb' and mode != 'wt':
36
36
            raise ValueError("invalid AtomicFile mode %r" % mode)
37
37
 
48
48
 
49
49
        self.write = self.f.write
50
50
        self.closed = False
 
51
        self._new_mode = new_mode
51
52
 
52
53
 
53
54
    def __repr__(self):
67
68
        self.f = None
68
69
        
69
70
        try:
70
 
            stat = os.lstat(self.realfilename)
71
 
            os.chmod(self.tmpfilename, stat.st_mode)
 
71
            if self._new_mode is None:
 
72
                self._new_mode = os.lstat(self.realfilename).st_mode
72
73
        except OSError, e:
73
74
            if e.errno != errno.ENOENT:
74
75
                raise
 
76
        else:
 
77
            os.chmod(self.tmpfilename, self._new_mode)
 
78
 
75
79
        rename(self.tmpfilename, self.realfilename)
76
80
 
77
81