206
206
self.assertRaises(NoSuchFile,
207
207
t.put_bytes, 'path/doesnt/exist/c', 'contents')
209
def test_non_atomic_put(self):
210
t = self.get_transport()
213
self.assertRaises(TransportNotPossible,
214
t.non_atomic_put, 'a', StringIO('some text for a\n'))
217
self.failIf(t.has('a'))
218
t.non_atomic_put('a', StringIO('some text for a\n'))
219
self.failUnless(t.has('a'))
220
self.check_transport_contents('some text for a\n', t, 'a')
221
# Put also replaces contents
222
t.non_atomic_put('a', StringIO('new\ncontents for\na\n'))
223
self.check_transport_contents('new\ncontents for\na\n', t, 'a')
225
# Make sure we can create another file
226
t.non_atomic_put('d', StringIO('contents for\nd\n'))
227
# And overwrite 'a' with empty contents
228
t.non_atomic_put('a', StringIO(''))
229
self.check_transport_contents('contents for\nd\n', t, 'd')
230
self.check_transport_contents('', t, 'a')
232
self.assertRaises(NoSuchFile, t.non_atomic_put, 'no/such/path',
233
StringIO('contents\n'))
234
# Now test the create_parent flag
235
self.assertRaises(NoSuchFile, t.non_atomic_put, 'dir/a',
236
StringIO('contents\n'))
237
self.failIf(t.has('dir/a'))
238
t.non_atomic_put('dir/a', StringIO('contents for dir/a\n'),
239
create_parent_dir=True)
240
self.check_transport_contents('contents for dir/a\n', t, 'dir/a')
242
# But we still get NoSuchFile if we can't make the parent dir
243
self.assertRaises(NoSuchFile, t.non_atomic_put, 'not/there/a',
244
StringIO('contents\n'))
209
246
def test_put_file_permissions(self):
210
248
t = self.get_transport()
212
250
if t.is_readonly():
260
298
t.put_bytes('nomode', 'test text\n', mode=None)
261
299
self.assertTransportMode(t, 'nomode', 0666 & ~umask)
301
def test_non_atomic_put_permissions(self):
302
t = self.get_transport()
306
if not t._can_roundtrip_unix_modebits():
307
# Can't roundtrip, so no need to run this test
309
t.non_atomic_put('mode644', StringIO('test text\n'), mode=0644)
310
self.assertTransportMode(t, 'mode644', 0644)
311
t.non_atomic_put('mode666', StringIO('test text\n'), mode=0666)
312
self.assertTransportMode(t, 'mode666', 0666)
313
t.non_atomic_put('mode600', StringIO('test text\n'), mode=0600)
314
self.assertTransportMode(t, 'mode600', 0600)
315
# Yes, you can non_atomic_put a file such that it becomes readonly
316
t.non_atomic_put('mode400', StringIO('test text\n'), mode=0400)
317
self.assertTransportMode(t, 'mode400', 0400)
319
# The default permissions should be based on the current umask
320
umask = osutils.get_umask()
321
t.non_atomic_put('nomode', StringIO('test text\n'), mode=None)
322
self.assertTransportMode(t, 'nomode', 0666 & ~umask)
263
324
def test_mkdir(self):
264
325
t = self.get_transport()