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.encodingutil import unicode_to_url, listdir_unicode, quote_output, to_str
from allmydata.util.assertutil import precondition
def make_tahoe_subdirectory(nodeurl, parent_writecap, name):
url = nodeurl + "/".join(["uri",
urllib.quote(parent_writecap),
- urllib.quote(name),
+ urllib.quote(unicode_to_url(name)),
]) + "?t=mkdir"
resp = do_http("POST", url)
if resp.status in (200, 201):
self.children = {}
children = listdir_unicode(self.pathname)
for i,n in enumerate(children):
- self.progressfunc("examining %d of %d" % (i, len(children)))
+ self.progressfunc("examining %d of %d" % (i+1, len(children)))
pn = os.path.join(self.pathname, n)
if os.path.isdir(pn):
child = LocalDirectorySource(self.progressfunc, pn)
self.children = {}
children = listdir_unicode(self.pathname)
for i,n in enumerate(children):
- self.progressfunc("examining %d of %d" % (i, len(children)))
+ self.progressfunc("examining %d of %d" % (i+1, len(children)))
n = unicode(n)
pn = os.path.join(self.pathname, n)
if os.path.isdir(pn):
return
self.children = {}
for i,(name, data) in enumerate(self.children_d.items()):
- self.progressfunc("examining %d of %d" % (i, len(self.children_d)))
+ self.progressfunc("examining %d of %d" % (i+1, len(self.children_d)))
if data[0] == "filenode":
mutable = data[1].get("mutable", False)
writecap = to_str(data[1].get("rw_uri"))
return
self.children = {}
for i,(name, data) in enumerate(self.children_d.items()):
- self.progressfunc("examining %d of %d" % (i, len(self.children_d)))
+ self.progressfunc("examining %d of %d" % (i+1, len(self.children_d)))
if data[0] == "filenode":
mutable = data[1].get("mutable", False)
writecap = to_str(data[1].get("rw_uri"))
url = self.nodeurl + "uri"
if not hasattr(inf, "seek"):
inf = inf.read()
- filecap = PUT(url, inf)
- # TODO: this always creates immutable files. We might want an option
- # to always create mutable files, or to copy mutable files into new
- # mutable files.
- self.new_children[name] = filecap
+
+ if self.children is None:
+ self.populate(False)
+
+ # Check to see if we already have a mutable file by this name.
+ # If so, overwrite that file in place.
+ if name in self.children and self.children[name].mutable:
+ self.children[name].put_file(inf)
+ else:
+ filecap = PUT(url, inf)
+ # TODO: this always creates immutable files. We might want an option
+ # to always create mutable files, or to copy mutable files into new
+ # mutable files.
+ self.new_children[name] = filecap
def put_uri(self, name, filecap):
self.new_children[name] = filecap
return self.copy_file(source, target)
if isinstance(target, (LocalDirectoryTarget, TahoeDirectoryTarget)):
- # We're copying to an existing directory -- make sure that we
+ # We're copying to an existing directory -- make sure that we
# have target names for everything
for (name, source) in sources:
if name is None and isinstance(source, TahoeFileSource):
rootcap, path = get_alias(self.aliases, destination_spec, None)
if rootcap == DefaultAliasMarker:
# no alias, so this is a local file
- pathname = os.path.abspath(os.path.expanduser(path.decode('utf-8')))
+ pathname = abspath_expanduser_unicode(path.decode('utf-8'))
if not os.path.exists(pathname):
t = LocalMissingTarget(pathname)
elif os.path.isdir(pathname):
rootcap, path = get_alias(self.aliases, source_spec, None)
if rootcap == DefaultAliasMarker:
# no alias, so this is a local file
- pathname = os.path.abspath(os.path.expanduser(path.decode('utf-8')))
+ pathname = abspath_expanduser_unicode(path.decode('utf-8'))
name = os.path.basename(pathname)
if not os.path.exists(pathname):
raise MissingSourceError(source_spec)
for (name,s) in source_files:
self.attach_to_target(s, name, target)
- self.files_to_copy += 1
for source in source_dirs:
self.assign_targets(source, target)