def __init__(self, name, quotefn=quote_output):
TahoeError.__init__(self, "No such file or directory %s" % quotefn(name))
+class FilenameWithTrailingSlashError(TahoeError):
+ def __init__(self, name, quotefn=quote_output):
+ TahoeError.__init__(self, "source '%s' is not a directory, but ends with a slash" % quotefn(name))
+
+class WeirdSourceError(TahoeError):
+ def __init__(self, absname):
+ quoted = quote_local_unicode_path(absname)
+ TahoeError.__init__(self, "source '%s' is neither a file nor a directory, I can't handle it" % quoted)
def GET_to_file(url):
resp = do_http("GET", url)
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
sources = [] # list of source objects
for ss in source_specs:
- si = self.get_source_info(ss)
+ try:
+ si = self.get_source_info(ss)
+ except FilenameWithTrailingSlashError as e:
+ self.to_stderr(str(e))
+ return 1
precondition(isinstance(si, FileSources + DirectorySources), si)
sources.append(si)
precondition(isinstance(source_spec, unicode), source_spec)
rootcap, path_utf8 = get_alias(self.aliases, source_spec, None)
path = path_utf8.decode("utf-8")
+ # any trailing slash is removed in abspath_expanduser_unicode(), so
+ # make a note of it here, to throw an error later
+ had_trailing_slash = path.endswith("/")
if rootcap == DefaultAliasMarker:
# no alias, so this is a local file
pathname = abspath_expanduser_unicode(path)
if os.path.isdir(pathname):
t = LocalDirectorySource(self.progress, pathname, name)
else:
- assert os.path.isfile(pathname)
+ if had_trailing_slash:
+ raise FilenameWithTrailingSlashError(source_spec,
+ quotefn=quote_local_unicode_path)
+ if not os.path.isfile(pathname):
+ raise WeirdSourceError(pathname)
t = LocalFileSource(pathname, name) # non-empty
else:
# this is a tahoe object
self.progress, name)
t.init_from_parsed(parsed)
else:
+ if had_trailing_slash:
+ raise FilenameWithTrailingSlashError(source_spec)
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
# 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.