From: Brian Warner Date: Wed, 29 Jul 2015 00:39:39 +0000 (-0700) Subject: Merge branch '2447-cp-overwrite' X-Git-Tag: allmydata-tahoe-1.10.2b1~2 X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=06c190e28cf68a84ea403f9b03369c7e27debb9b;hp=28399b689203a0841880cc03b378dcc0a696d8a3;p=tahoe-lafs%2Ftahoe-lafs.git Merge branch '2447-cp-overwrite' --- diff --git a/src/allmydata/scripts/tahoe_cp.py b/src/allmydata/scripts/tahoe_cp.py index b603d6ba..351b6a33 100644 --- a/src/allmydata/scripts/tahoe_cp.py +++ b/src/allmydata/scripts/tahoe_cp.py @@ -496,8 +496,9 @@ class Copier: def try_copy(self): """ - All usage errors are caught here, not in a subroutine. This bottoms - out in copy_file_to_file() or copy_things_to_directory(). + All usage errors (except for target filename collisions) are caught + here, not in a subroutine. This bottoms out in copy_file_to_file() or + copy_things_to_directory(). """ source_specs = self.options.sources destination_spec = self.options.destination @@ -735,6 +736,23 @@ class Copier: # sourceobject) dicts for all the files that need to wind up there. targetmap = self.build_targetmap(sources, target) + # target name collisions are an error + collisions = [] + for target, sources in targetmap.items(): + target_names = {} + for source in sources: + name = source.basename() + if name in target_names: + collisions.append((target, source, target_names[name])) + else: + target_names[name] = source + if collisions: + self.to_stderr("cannot copy multiple files with the same name into the same target directory") + # I'm not sure how to show where the collisions are coming from + #for (target, source1, source2) in collisions: + # self.to_stderr(source1.basename()) + return 1 + # step four: walk through the list of targets. For each one, copy all # the files. If the target is a TahoeDirectory, upload and create # read-caps, then do a set_children to the target directory. diff --git a/src/allmydata/test/test_cli_cp.py b/src/allmydata/test/test_cli_cp.py index 65f4e4a1..7e8bb02f 100644 --- a/src/allmydata/test/test_cli_cp.py +++ b/src/allmydata/test/test_cli_cp.py @@ -787,11 +787,11 @@ cp -r $PARENTCAP/dir3/file3 $DIRCAP $PARENTCAP/dir2 $FILECAP to/missing/ : E2-DE cp -r $PARENTCAP/dir4 to : to/dir4/emptydir/ cp -r $PARENTCAP/dir4 to/ : to/dir4/emptydir/ -# name collisions: ensure files are copied in order -cp -r $PARENTCAP/dir6/dir $PARENTCAP/dir5/dir to : to/dir/collide=5 -cp -r $PARENTCAP/dir5/dir $PARENTCAP/dir6/dir to : to/dir/collide=6 -cp -r $DIRCAP6 $DIRCAP5 to : to/dir/collide=5 -cp -r $DIRCAP5 $DIRCAP6 to : to/dir/collide=6 +# name collisions should cause errors, not overwrites +cp -r $PARENTCAP/dir6/dir $PARENTCAP/dir5/dir to : E9-COLLIDING-TARGETS +cp -r $PARENTCAP/dir5/dir $PARENTCAP/dir6/dir to : E9-COLLIDING-TARGETS +cp -r $DIRCAP6 $DIRCAP5 to : E9-COLLIDING-TARGETS +cp -r $DIRCAP5 $DIRCAP6 to : E9-COLLIDING-TARGETS """ @@ -952,6 +952,8 @@ class CopyOut(GridTestMixin, CLITestMixin, unittest.TestCase): if (err.startswith("source ") and "is not a directory, but ends with a slash" in err): return set(["E8-BADSLASH"]) + if err == "cannot copy multiple files with the same name into the same target directory": + return set(["E9-COLLIDING-TARGETS"]) self.fail("unrecognized error ('%s') %s" % (case, res)) d.addCallback(_check) return d