~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-05 21:20:24 UTC
  • mto: (1946.2.8 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1988.
  • Revision ID: john@arbash-meinel.com-20060905212024-39f58d0f5acd74a4
Deprecate 'Transport.append' in favor of Transport.append_file or Transport.append_bytes

Show diffs side-by-side

added added

removed removed

Lines of Context:
201
201
        except (IOError, OSError),e:
202
202
            self._translate_error(e, path)
203
203
 
204
 
    def append(self, relpath, f, mode=None):
205
 
        """Append the text in the file-like object into the final location."""
 
204
    def _get_append_file(self, relpath, mode=None):
 
205
        """Call os.open() for the given relpath"""
206
206
        abspath = self._abspath(relpath)
207
207
        if mode is None:
208
208
            # os.open() will automatically use the umask
210
210
        else:
211
211
            local_mode = mode
212
212
        try:
213
 
            fd = os.open(abspath, _append_flags, local_mode)
 
213
            return os.open(abspath, _append_flags, local_mode)
214
214
        except (IOError, OSError),e:
215
215
            self._translate_error(e, relpath)
 
216
 
 
217
    def _check_mode_and_size(self, fd, mode=None):
 
218
        """Check the mode of the file, and return the current size"""
 
219
        st = os.fstat(fd)
 
220
        if mode is not None and mode != S_IMODE(st.st_mode):
 
221
            # Because of umask, we may still need to chmod the file.
 
222
            # But in the general case, we won't have to
 
223
            os.chmod(abspath, mode)
 
224
        return st.st_size
 
225
 
 
226
    def append_file(self, relpath, f, mode=None):
 
227
        """Append the text in the file-like object into the final location."""
 
228
        fd = self._get_append_file(relpath, mode=mode)
216
229
        try:
217
 
            st = os.fstat(fd)
218
 
            result = st.st_size
219
 
            if mode is not None and mode != S_IMODE(st.st_mode):
220
 
                # Because of umask, we may still need to chmod the file.
221
 
                # But in the general case, we won't have to
222
 
                os.chmod(abspath, mode)
 
230
            result = self._check_mode_and_size(fd, mode=mode)
223
231
            self._pump_to_fd(f, fd)
224
232
        finally:
225
233
            os.close(fd)
226
234
        return result
227
235
 
 
236
    def append_bytes(self, relpath, bytes, mode=None):
 
237
        """Append the text in the string into the final location."""
 
238
        fd = self._get_append_file(relpath, mode=mode)
 
239
        try:
 
240
            result = self._check_mode_and_size(fd, mode=mode)
 
241
            os.write(fd, bytes)
 
242
        finally:
 
243
            os.close(fd)
 
244
        return result
 
245
 
228
246
    def _pump_to_fd(self, fromfile, to_fd):
229
247
        """Copy contents of one file to another."""
230
248
        BUFSIZE = 32768