From ca9bcf5253aac0951d27b0868029dbbb47a40455 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Mon, 25 Aug 2014 19:09:40 +0100 Subject: [PATCH] Use absolute paths in tahoe cp and tahoe backup. refs #2235 Signed-off-by: Daira Hopwood --- src/allmydata/scripts/cli.py | 2 +- src/allmydata/scripts/tahoe_backup.py | 6 +++--- src/allmydata/scripts/tahoe_cp.py | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/allmydata/scripts/cli.py b/src/allmydata/scripts/cli.py index 4fb9b66c..e0e505df 100644 --- a/src/allmydata/scripts/cli.py +++ b/src/allmydata/scripts/cli.py @@ -347,7 +347,7 @@ class BackupOptions(FilesystemOptions): self['exclude'] = set() def parseArgs(self, localdir, topath): - self.from_dir = argv_to_unicode(localdir) + self.from_dir = argv_to_abspath(localdir) self.to_dir = argv_to_unicode(topath) def getSynopsis(self): diff --git a/src/allmydata/scripts/tahoe_backup.py b/src/allmydata/scripts/tahoe_backup.py index e52407a6..f12b3171 100644 --- a/src/allmydata/scripts/tahoe_backup.py +++ b/src/allmydata/scripts/tahoe_backup.py @@ -12,7 +12,7 @@ from allmydata.scripts import backupdb from allmydata.util.encodingutil import listdir_unicode, quote_output, \ quote_local_unicode_path, to_str, FilenameEncodingError, unicode_to_url from allmydata.util.assertutil import precondition -from allmydata.util.fileutil import abspath_expanduser_unicode +from allmydata.util.fileutil import abspath_expanduser_unicode, precondition_abspath def get_local_metadata(path): @@ -160,7 +160,7 @@ class BackerUpper: print >>self.options.stderr, msg def process(self, localpath): - precondition(isinstance(localpath, unicode), localpath) + precondition_abspath(localpath) # returns newdircap quoted_path = quote_local_unicode_path(localpath) @@ -289,7 +289,7 @@ class BackerUpper: # This function will raise an IOError exception when called on an unreadable file def upload(self, childpath): - precondition(isinstance(childpath, unicode), childpath) + precondition_abspath(childpath) #self.verboseprint("uploading %s.." % quote_local_unicode_path(childpath)) metadata = get_local_metadata(childpath) diff --git a/src/allmydata/scripts/tahoe_cp.py b/src/allmydata/scripts/tahoe_cp.py index f9b01142..25c3b2e4 100644 --- a/src/allmydata/scripts/tahoe_cp.py +++ b/src/allmydata/scripts/tahoe_cp.py @@ -9,7 +9,7 @@ from allmydata.scripts.common import get_alias, escape_path, \ from allmydata.scripts.common_http import do_http, HTTPError from allmydata import uri from allmydata.util import fileutil -from allmydata.util.fileutil import abspath_expanduser_unicode +from allmydata.util.fileutil import abspath_expanduser_unicode, precondition_abspath from allmydata.util.encodingutil import unicode_to_url, listdir_unicode, quote_output, \ quote_local_unicode_path, to_str from allmydata.util.assertutil import precondition @@ -62,37 +62,34 @@ def make_tahoe_subdirectory(nodeurl, parent_writecap, name): class LocalFileSource: def __init__(self, pathname): - precondition(isinstance(pathname, unicode), pathname) + precondition_abspath(pathname) self.pathname = pathname def need_to_copy_bytes(self): return True def open(self, caps_only): - return open(os.path.expanduser(self.pathname), "rb") - + return open(self.pathname, "rb") class LocalFileTarget: def __init__(self, pathname): - precondition(isinstance(pathname, unicode), pathname) + precondition_abspath(pathname) self.pathname = pathname def put_file(self, inf): fileutil.put_file(self.pathname, inf) - class LocalMissingTarget: def __init__(self, pathname): - precondition(isinstance(pathname, unicode), pathname) + precondition_abspath(pathname) self.pathname = pathname def put_file(self, inf): fileutil.put_file(self.pathname, inf) - class LocalDirectorySource: def __init__(self, progressfunc, pathname): - precondition(isinstance(pathname, unicode), pathname) + precondition_abspath(pathname) self.progressfunc = progressfunc self.pathname = pathname @@ -120,7 +117,7 @@ class LocalDirectorySource: class LocalDirectoryTarget: def __init__(self, progressfunc, pathname): - precondition(isinstance(pathname, unicode), pathname) + precondition_abspath(pathname) self.progressfunc = progressfunc self.pathname = pathname @@ -161,6 +158,7 @@ class LocalDirectoryTarget: def set_children(self): pass + class TahoeFileSource: def __init__(self, nodeurl, mutable, writecap, readcap): self.nodeurl = nodeurl @@ -519,6 +517,8 @@ class Copier: def to_stderr(self, text): print >>self.stderr, text + # FIXME reduce the amount of near-duplicate code between get_target_info and get_source_info. + def get_target_info(self, destination_spec): rootcap, path = get_alias(self.aliases, destination_spec, None) if rootcap == DefaultAliasMarker: -- 2.45.2