157
def non_atomic_put(self, relpath, f, mode=None):
158
def non_atomic_put(self, relpath, f, mode=None, create_parent_dir=False):
158
159
"""Copy the file-like object into the target location.
160
161
This function is not strictly safe to use. It is only meant to
166
167
:param f: File-like object.
167
168
:param mode: Possible access permissions for new file.
168
169
None means do not set remote permissions.
170
:param create_parent_dir: If we cannot create the target file because
171
the parent directory does not exist, go ahead and
172
create it, and then try again.
170
174
abspath = self._abspath(relpath)
177
181
fd = os.open(abspath, _non_atomic_put_flags, local_mode)
178
182
except (IOError, OSError),e:
179
self._translate_error(e, relpath)
183
# We couldn't create the file, maybe we need to create
184
# the parent directory, and try again
185
if (not create_parent_dir
186
or e.errno not in (errno.ENOENT,errno.ENOTDIR)):
187
self._translate_error(e, relpath)
188
parent_dir = os.path.dirname(abspath)
190
self._translate_error(e, relpath)
193
except (IOError, OSError), e:
194
self._translate_error(e, relpath)
195
# We created the parent directory, lets try to open the
198
fd = os.open(abspath, _non_atomic_put_flags, local_mode)
199
except (IOError, OSError), e:
200
self._translate_error(e, relpath)
181
202
st = os.fstat(fd)
182
203
if mode is not None and mode != S_IMODE(st.st_mode):