201
201
except (IOError, OSError),e:
202
202
self._translate_error(e, path)
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)
208
208
# os.open() will automatically use the umask
211
211
local_mode = mode
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)
217
def _check_mode_and_size(self, fd, mode=None):
218
"""Check the mode of the file, and return the current size"""
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)
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)
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)
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)
240
result = self._check_mode_and_size(fd, mode=mode)
228
246
def _pump_to_fd(self, fromfile, to_fd):
229
247
"""Copy contents of one file to another."""