Browse code

don't allow mv/cp of multiple files to single file

When trying to cp/mv multiple files, make sure the destination
has a trailing slash so it is treated as a directory. Otherwise,
multiple files can get moved to a single file, leading to data
loss.

Guy Gur-Ari authored on 2017/04/08 10:25:08
Showing 2 changed files
... ...
@@ -393,6 +393,20 @@ f.close()
393 393
 ## ====== Clean up local destination dir
394 394
 test_flushdir("Clean testsuite-out/", "testsuite-out")
395 395
 
396
+## ====== Move multiple files into directory
397
+must_find = ["'%s/urandom1.bin' -> '%s/dir/urandom1.bin'" % (pbucket(1),pbucket(1)), "'%s/urandom2.bin' -> '%s/dir/urandom2.bin'" % (pbucket(1),pbucket(1))]
398
+must_not_find = ["'%s/urandom1.bin' -> '%s/dir'" % (pbucket(1),pbucket(1)), "'%s/urandom2.bin' -> '%s/dir'" % (pbucket(1),pbucket(1))]
399
+os.system('dd if=/dev/urandom of=testsuite-out/urandom1.bin bs=1k count=1 > /dev/null 2>&1')
400
+os.system('dd if=/dev/urandom of=testsuite-out/urandom2.bin bs=1k count=1 > /dev/null 2>&1')
401
+test_s3cmd("Put multiple files", ['put', 'testsuite-out/urandom1.bin', 'testsuite-out/urandom2.bin', '%s/' % pbucket(1)],
402
+           must_find = ["%s/urandom1.bin" % pbucket(1), "%s/urandom2.bin" % pbucket(1)])
403
+test_s3cmd("Move multiple files", ['mv', '%s/urandom1.bin' % pbucket(1), '%s/urandom2.bin' % pbucket(1), '%s/dir' % pbucket(1)],
404
+           must_find = must_find,
405
+           must_not_find = must_not_find)
406
+
407
+## ====== Clean up local destination dir
408
+test_flushdir("Clean testsuite-out/", "testsuite-out")
409
+
396 410
 ## ====== Sync from S3
397 411
 must_find = [ "'%s/xyz/binary/random-crap.md5' -> 'testsuite-out/xyz/binary/random-crap.md5'" % pbucket(1) ]
398 412
 if have_encoding:
... ...
@@ -400,7 +414,6 @@ if have_encoding:
400 400
 test_s3cmd("Sync from S3", ['sync', '%s/xyz' % pbucket(1), 'testsuite-out'],
401 401
     must_find = must_find)
402 402
 
403
-
404 403
 ## ====== Remove 'demo' directory
405 404
 test_rmdir("Remove 'dir-test/'", "testsuite-out/xyz/dir-test/")
406 405
 
... ...
@@ -812,6 +812,8 @@ def subcmd_cp_mv(args, process_fce, action_str, message):
812 812
         for key in remote_list:
813 813
             remote_list[key]['dest_name'] = destination_base + key
814 814
     else:
815
+        if len(remote_list) > 1 and not destination_base.endswith("/"):
816
+            destination_base += "/"
815 817
         for key in remote_list:
816 818
             if destination_base.endswith("/"):
817 819
                 remote_list[key]['dest_name'] = destination_base + key