]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/scripts/tahoe_cp.py
tahoe cp: ignore trailing slash on source arguments
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / tahoe_cp.py
index f55279bec8b5174d8784bf7810b011def7ec933a..a5cfe16a1a25b7b65e9ca9d9856256457b7da9a4 100644 (file)
@@ -151,6 +151,7 @@ class LocalDirectoryTarget:
 
     def get_child_target(self, name):
         precondition(isinstance(name, unicode), name)
+        precondition(len(name), name) # don't want ""
         if self.children is None:
             self.populate(recurse=False)
         if name in self.children:
@@ -559,7 +560,7 @@ class Copier:
         _assert(isinstance(target, DirectoryTargets + MissingTargets), target)
 
         for source in sources:
-            if isinstance(source, FileSources) and not source.basename():
+            if isinstance(source, FileSources) and source.basename() is None:
                 self.to_stderr("when copying into a directory, all source files must have names, but %s is unnamed" % quote_output(source_specs[0]))
                 return 1
         return self.copy_things_to_directory(sources, target)
@@ -637,6 +638,8 @@ class Copier:
             url = self.nodeurl + "uri/%s" % urllib.quote(rootcap)
             name = None
             if path:
+                if path.endswith("/"):
+                    path = path[:-1]
                 url += "/" + escape_path(path)
                 last_slash = path.rfind(u"/")
                 name = path
@@ -659,13 +662,6 @@ class Copier:
                 writecap = to_str(d.get("rw_uri"))
                 readcap = to_str(d.get("ro_uri"))
                 mutable = d.get("mutable", False) # older nodes don't provide it
-
-                last_slash = source_spec.rfind(u"/")
-                if last_slash != -1:
-                    # TODO: this looks funny and redundant with the 'name'
-                    # assignment above. cf #2329
-                    name = source_spec[last_slash+1:]
-
                 t = TahoeFileSource(self.nodeurl, mutable, writecap, readcap, name)
         return t
 
@@ -778,7 +774,7 @@ class Copier:
                 subtarget = target.get_child_target(name)
                 self.assign_targets(targetmap, child, subtarget)
             else:
-                precondition(isinstance(child, FileSources), child)
+                _assert(isinstance(child, FileSources), child)
                 targetmap[target].append(child)
 
     def copy_to_targetmap(self, targetmap):
@@ -789,9 +785,9 @@ class Copier:
         targets_finished = 0
 
         for target, sources in targetmap.items():
-            precondition(isinstance(target, DirectoryTargets), target)
+            _assert(isinstance(target, DirectoryTargets), target)
             for source in sources:
-                precondition(isinstance(source, FileSources), source)
+                _assert(isinstance(source, FileSources), source)
                 self.copy_file_into_dir(source, source.basename(), target)
                 files_copied += 1
                 self.progress("%d/%d files, %d/%d directories" %
@@ -803,8 +799,7 @@ class Copier:
                           (targets_finished, len(targetmap)))
 
     def count_files_to_copy(self, targetmap):
-        files_to_copy = sum([len(sources) for sources in targetmap.values()])
-        return files_to_copy
+        return sum([len(sources) for sources in targetmap.values()])
 
     def copy_file_into_dir(self, source, name, target):
         precondition(isinstance(source, FileSources), source)