]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/tahoe_cp.py
tahoe_cp: delete copy_to_directory() code
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / tahoe_cp.py
1
2 import os.path
3 import urllib
4 import simplejson
5 from cStringIO import StringIO
6 from twisted.python.failure import Failure
7 from allmydata.scripts.common import get_alias, escape_path, \
8                                      DefaultAliasMarker, TahoeError
9 from allmydata.scripts.common_http import do_http, HTTPError
10 from allmydata import uri
11 from allmydata.util import fileutil
12 from allmydata.util.fileutil import abspath_expanduser_unicode, precondition_abspath
13 from allmydata.util.encodingutil import unicode_to_url, listdir_unicode, quote_output, \
14     quote_local_unicode_path, to_str
15 from allmydata.util.assertutil import precondition
16
17
18 class MissingSourceError(TahoeError):
19     def __init__(self, name, quotefn=quote_output):
20         TahoeError.__init__(self, "No such file or directory %s" % quotefn(name))
21
22
23 def GET_to_file(url):
24     resp = do_http("GET", url)
25     if resp.status == 200:
26         return resp
27     raise HTTPError("Error during GET", resp)
28
29 def GET_to_string(url):
30     f = GET_to_file(url)
31     return f.read()
32
33 def PUT(url, data):
34     resp = do_http("PUT", url, data)
35     if resp.status in (200, 201):
36         return resp.read()
37     raise HTTPError("Error during PUT", resp)
38
39 def POST(url, data):
40     resp = do_http("POST", url, data)
41     if resp.status in (200, 201):
42         return resp.read()
43     raise HTTPError("Error during POST", resp)
44
45 def mkdir(targeturl):
46     url = targeturl + "?t=mkdir"
47     resp = do_http("POST", url)
48     if resp.status in (200, 201):
49         return resp.read().strip()
50     raise HTTPError("Error during mkdir", resp)
51
52 def make_tahoe_subdirectory(nodeurl, parent_writecap, name):
53     url = nodeurl + "/".join(["uri",
54                               urllib.quote(parent_writecap),
55                               urllib.quote(unicode_to_url(name)),
56                               ]) + "?t=mkdir"
57     resp = do_http("POST", url)
58     if resp.status in (200, 201):
59         return resp.read().strip()
60     raise HTTPError("Error during mkdir", resp)
61
62
63 class LocalFileSource:
64     def __init__(self, pathname, basename):
65         precondition_abspath(pathname)
66         self.pathname = pathname
67         self._basename = basename
68
69     def basename(self):
70         return self._basename
71
72     def need_to_copy_bytes(self):
73         return True
74
75     def open(self, caps_only):
76         return open(self.pathname, "rb")
77
78 class LocalFileTarget:
79     def __init__(self, pathname):
80         precondition_abspath(pathname)
81         self.pathname = pathname
82
83     def put_file(self, inf):
84         fileutil.put_file(self.pathname, inf)
85
86 class LocalMissingTarget:
87     def __init__(self, pathname):
88         precondition_abspath(pathname)
89         self.pathname = pathname
90
91     def put_file(self, inf):
92         fileutil.put_file(self.pathname, inf)
93
94 class LocalDirectorySource:
95     def __init__(self, progressfunc, pathname, basename):
96         precondition_abspath(pathname)
97
98         self.progressfunc = progressfunc
99         self.pathname = pathname
100         self.children = None
101         self._basename = basename
102
103     def basename(self):
104         return self._basename
105
106     def populate(self, recurse):
107         if self.children is not None:
108             return
109         self.children = {}
110         children = listdir_unicode(self.pathname)
111         for i,n in enumerate(children):
112             self.progressfunc("examining %d of %d" % (i+1, len(children)))
113             pn = os.path.join(self.pathname, n)
114             if os.path.isdir(pn):
115                 child = LocalDirectorySource(self.progressfunc, pn, n)
116                 self.children[n] = child
117                 if recurse:
118                     child.populate(True)
119             elif os.path.isfile(pn):
120                 self.children[n] = LocalFileSource(pn, n)
121             else:
122                 # Could be dangling symlink; probably not copy-able.
123                 # TODO: output a warning
124                 pass
125
126 class LocalDirectoryTarget:
127     def __init__(self, progressfunc, pathname):
128         precondition_abspath(pathname)
129
130         self.progressfunc = progressfunc
131         self.pathname = pathname
132         self.children = None
133
134     def populate(self, recurse):
135         if self.children is not None:
136             return
137         self.children = {}
138         children = listdir_unicode(self.pathname)
139         for i,n in enumerate(children):
140             self.progressfunc("examining %d of %d" % (i+1, len(children)))
141             pn = os.path.join(self.pathname, n)
142             if os.path.isdir(pn):
143                 child = LocalDirectoryTarget(self.progressfunc, pn)
144                 self.children[n] = child
145                 if recurse:
146                     child.populate(True)
147             else:
148                 assert os.path.isfile(pn)
149                 self.children[n] = LocalFileTarget(pn)
150
151     def get_child_target(self, name):
152         precondition(isinstance(name, unicode), name)
153         if self.children is None:
154             self.populate(False)
155         if name in self.children:
156             return self.children[name]
157         pathname = os.path.join(self.pathname, name)
158         os.makedirs(pathname)
159         return LocalDirectoryTarget(self.progressfunc, pathname)
160
161     def put_file(self, name, inf):
162         precondition(isinstance(name, unicode), name)
163         pathname = os.path.join(self.pathname, name)
164         fileutil.put_file(pathname, inf)
165
166     def set_children(self):
167         pass
168
169
170 class TahoeFileSource:
171     def __init__(self, nodeurl, mutable, writecap, readcap, basename):
172         self.nodeurl = nodeurl
173         self.mutable = mutable
174         self.writecap = writecap
175         self.readcap = readcap
176         self._basename = basename # unicode, or None for raw filecaps
177
178     def basename(self):
179         return self._basename
180
181     def need_to_copy_bytes(self):
182         if self.mutable:
183             return True
184         return False
185
186     def open(self, caps_only):
187         if caps_only:
188             return StringIO(self.readcap)
189         url = self.nodeurl + "uri/" + urllib.quote(self.readcap)
190         return GET_to_file(url)
191
192     def bestcap(self):
193         return self.writecap or self.readcap
194
195 class TahoeFileTarget:
196     def __init__(self, nodeurl, mutable, writecap, readcap, url):
197         self.nodeurl = nodeurl
198         self.mutable = mutable
199         self.writecap = writecap
200         self.readcap = readcap
201         self.url = url
202
203     def put_file(self, inf):
204         # We want to replace this object in-place.
205         assert self.url
206         # our do_http() call currently requires a string or a filehandle with
207         # a real .seek
208         if not hasattr(inf, "seek"):
209             inf = inf.read()
210         PUT(self.url, inf)
211         # TODO: this always creates immutable files. We might want an option
212         # to always create mutable files, or to copy mutable files into new
213         # mutable files. ticket #835
214
215 class TahoeDirectorySource:
216     def __init__(self, nodeurl, cache, progressfunc, basename):
217         self.nodeurl = nodeurl
218         self.cache = cache
219         self.progressfunc = progressfunc
220         self._basename = basename # unicode, or None for raw dircaps
221
222     def basename(self):
223         return self._basename
224
225     def init_from_grid(self, writecap, readcap):
226         self.writecap = writecap
227         self.readcap = readcap
228         bestcap = writecap or readcap
229         url = self.nodeurl + "uri/%s" % urllib.quote(bestcap)
230         resp = do_http("GET", url + "?t=json")
231         if resp.status != 200:
232             raise HTTPError("Error examining source directory", resp)
233         parsed = simplejson.loads(resp.read())
234         nodetype, d = parsed
235         assert nodetype == "dirnode"
236         self.mutable = d.get("mutable", False) # older nodes don't provide it
237         self.children_d = dict( [(unicode(name),value)
238                                  for (name,value)
239                                  in d["children"].iteritems()] )
240         self.children = None
241
242     def init_from_parsed(self, parsed):
243         nodetype, d = parsed
244         self.writecap = to_str(d.get("rw_uri"))
245         self.readcap = to_str(d.get("ro_uri"))
246         self.mutable = d.get("mutable", False) # older nodes don't provide it
247         self.children_d = dict( [(unicode(name),value)
248                                  for (name,value)
249                                  in d["children"].iteritems()] )
250         self.children = None
251
252     def populate(self, recurse):
253         if self.children is not None:
254             return
255         self.children = {}
256         for i,(name, data) in enumerate(self.children_d.items()):
257             self.progressfunc("examining %d of %d" % (i+1, len(self.children_d)))
258             if data[0] == "filenode":
259                 mutable = data[1].get("mutable", False)
260                 writecap = to_str(data[1].get("rw_uri"))
261                 readcap = to_str(data[1].get("ro_uri"))
262                 self.children[name] = TahoeFileSource(self.nodeurl, mutable,
263                                                       writecap, readcap, name)
264             elif data[0] == "dirnode":
265                 writecap = to_str(data[1].get("rw_uri"))
266                 readcap = to_str(data[1].get("ro_uri"))
267                 if writecap and writecap in self.cache:
268                     child = self.cache[writecap]
269                 elif readcap and readcap in self.cache:
270                     child = self.cache[readcap]
271                 else:
272                     child = TahoeDirectorySource(self.nodeurl, self.cache,
273                                                  self.progressfunc, name)
274                     child.init_from_grid(writecap, readcap)
275                     if writecap:
276                         self.cache[writecap] = child
277                     if readcap:
278                         self.cache[readcap] = child
279                     if recurse:
280                         child.populate(True)
281                 self.children[name] = child
282             else:
283                 # TODO: there should be an option to skip unknown nodes.
284                 raise TahoeError("Cannot copy unknown nodes (ticket #839). "
285                                  "You probably need to use a later version of "
286                                  "Tahoe-LAFS to copy this directory.")
287
288 class TahoeMissingTarget:
289     def __init__(self, url):
290         self.url = url
291
292     def put_file(self, inf):
293         # We want to replace this object in-place.
294         if not hasattr(inf, "seek"):
295             inf = inf.read()
296         PUT(self.url, inf)
297         # TODO: this always creates immutable files. We might want an option
298         # to always create mutable files, or to copy mutable files into new
299         # mutable files.
300
301     def put_uri(self, filecap):
302         # I'm not sure this will always work
303         return PUT(self.url + "?t=uri", filecap)
304
305 class TahoeDirectoryTarget:
306     def __init__(self, nodeurl, cache, progressfunc):
307         self.nodeurl = nodeurl
308         self.cache = cache
309         self.progressfunc = progressfunc
310         self.new_children = {}
311
312     def init_from_parsed(self, parsed):
313         nodetype, d = parsed
314         self.writecap = to_str(d.get("rw_uri"))
315         self.readcap = to_str(d.get("ro_uri"))
316         self.mutable = d.get("mutable", False) # older nodes don't provide it
317         self.children_d = dict( [(unicode(name),value)
318                                  for (name,value)
319                                  in d["children"].iteritems()] )
320         self.children = None
321
322     def init_from_grid(self, writecap, readcap):
323         self.writecap = writecap
324         self.readcap = readcap
325         bestcap = writecap or readcap
326         url = self.nodeurl + "uri/%s" % urllib.quote(bestcap)
327         resp = do_http("GET", url + "?t=json")
328         if resp.status != 200:
329             raise HTTPError("Error examining target directory", resp)
330         parsed = simplejson.loads(resp.read())
331         nodetype, d = parsed
332         assert nodetype == "dirnode"
333         self.mutable = d.get("mutable", False) # older nodes don't provide it
334         self.children_d = dict( [(unicode(name),value)
335                                  for (name,value)
336                                  in d["children"].iteritems()] )
337         self.children = None
338
339     def just_created(self, writecap):
340         self.writecap = writecap
341         self.readcap = uri.from_string(writecap).get_readonly().to_string()
342         self.mutable = True
343         self.children_d = {}
344         self.children = {}
345
346     def populate(self, recurse):
347         if self.children is not None:
348             return
349         self.children = {}
350         for i,(name, data) in enumerate(self.children_d.items()):
351             self.progressfunc("examining %d of %d" % (i+1, len(self.children_d)))
352             if data[0] == "filenode":
353                 mutable = data[1].get("mutable", False)
354                 writecap = to_str(data[1].get("rw_uri"))
355                 readcap = to_str(data[1].get("ro_uri"))
356                 url = None
357                 if self.writecap:
358                     url = self.nodeurl + "/".join(["uri",
359                                                    urllib.quote(self.writecap),
360                                                    urllib.quote(unicode_to_url(name))])
361                 self.children[name] = TahoeFileTarget(self.nodeurl, mutable,
362                                                       writecap, readcap, url)
363             elif data[0] == "dirnode":
364                 writecap = to_str(data[1].get("rw_uri"))
365                 readcap = to_str(data[1].get("ro_uri"))
366                 if writecap and writecap in self.cache:
367                     child = self.cache[writecap]
368                 elif readcap and readcap in self.cache:
369                     child = self.cache[readcap]
370                 else:
371                     child = TahoeDirectoryTarget(self.nodeurl, self.cache,
372                                                  self.progressfunc)
373                     child.init_from_grid(writecap, readcap)
374                     if writecap:
375                         self.cache[writecap] = child
376                     if readcap:
377                         self.cache[readcap] = child
378                     if recurse:
379                         child.populate(True)
380                 self.children[name] = child
381             else:
382                 # TODO: there should be an option to skip unknown nodes.
383                 raise TahoeError("Cannot copy unknown nodes (ticket #839). "
384                                  "You probably need to use a later version of "
385                                  "Tahoe-LAFS to copy this directory.")
386
387     def get_child_target(self, name):
388         # return a new target for a named subdirectory of this dir
389         precondition(isinstance(name, unicode), name)
390         if self.children is None:
391             self.populate(False)
392         if name in self.children:
393             return self.children[name]
394         writecap = make_tahoe_subdirectory(self.nodeurl, self.writecap, name)
395         child = TahoeDirectoryTarget(self.nodeurl, self.cache,
396                                      self.progressfunc)
397         child.just_created(writecap)
398         self.children[name] = child
399         return child
400
401     def put_file(self, name, inf):
402         precondition(isinstance(name, unicode), name)
403         url = self.nodeurl + "uri"
404         if not hasattr(inf, "seek"):
405             inf = inf.read()
406
407         if self.children is None:
408             self.populate(False)
409
410         # Check to see if we already have a mutable file by this name.
411         # If so, overwrite that file in place.
412         if name in self.children and self.children[name].mutable:
413             self.children[name].put_file(inf)
414         else:
415             filecap = PUT(url, inf)
416             # TODO: this always creates immutable files. We might want an option
417             # to always create mutable files, or to copy mutable files into new
418             # mutable files.
419             self.new_children[name] = filecap
420
421     def put_uri(self, name, filecap):
422         precondition(isinstance(name, unicode), name)
423         self.new_children[name] = filecap
424
425     def set_children(self):
426         if not self.new_children:
427             return
428         url = (self.nodeurl + "uri/" + urllib.quote(self.writecap)
429                + "?t=set_children")
430         set_data = {}
431         for (name, filecap) in self.new_children.items():
432             # it just so happens that ?t=set_children will accept both file
433             # read-caps and write-caps as ['rw_uri'], and will handle either
434             # correctly. So don't bother trying to figure out whether the one
435             # we have is read-only or read-write.
436             # TODO: think about how this affects forward-compatibility for
437             # unknown caps
438             set_data[name] = ["filenode", {"rw_uri": filecap}]
439         body = simplejson.dumps(set_data)
440         POST(url, body)
441
442 FileSources = (LocalFileSource, TahoeFileSource)
443 DirectorySources = (LocalDirectorySource, TahoeDirectorySource)
444 FileTargets = (LocalFileTarget, TahoeFileTarget)
445 DirectoryTargets = (LocalDirectoryTarget, TahoeDirectoryTarget)
446 MissingTargets = (LocalMissingTarget, TahoeMissingTarget)
447
448 class Copier:
449
450     def do_copy(self, options, progressfunc=None):
451         if options['quiet']:
452             verbosity = 0
453         elif options['verbose']:
454             verbosity = 2
455         else:
456             verbosity = 1
457
458         nodeurl = options['node-url']
459         if nodeurl[-1] != "/":
460             nodeurl += "/"
461         self.nodeurl = nodeurl
462         self.progressfunc = progressfunc
463         self.options = options
464         self.aliases = options.aliases
465         self.verbosity = verbosity
466         self.stdout = options.stdout
467         self.stderr = options.stderr
468         if verbosity >= 2 and not self.progressfunc:
469             def progress(message):
470                 print >>self.stderr, message
471             self.progressfunc = progress
472         self.caps_only = options["caps-only"]
473         self.cache = {}
474         try:
475             status = self.try_copy()
476             return status
477         except TahoeError, te:
478             if verbosity >= 2:
479                 Failure().printTraceback(self.stderr)
480                 print >>self.stderr
481             te.display(self.stderr)
482             return 1
483
484     def try_copy(self):
485         source_specs = self.options.sources
486         destination_spec = self.options.destination
487         recursive = self.options["recursive"]
488
489         target = self.get_target_info(destination_spec)
490
491         sources = [] # list of source objects
492         for ss in source_specs:
493             sources.append(self.get_source_info(ss))
494
495         have_source_dirs = any([isinstance(s, DirectorySources)
496                                 for s in sources])
497
498         if have_source_dirs and not recursive:
499             self.to_stderr("cannot copy directories without --recursive")
500             return 1
501
502         if isinstance(target, FileTargets):
503             # cp STUFF foo.txt, where foo.txt already exists. This limits the
504             # possibilities considerably.
505             if len(sources) > 1:
506                 self.to_stderr("target %s is not a directory" % quote_output(destination_spec))
507                 return 1
508             if have_source_dirs:
509                 self.to_stderr("cannot copy directory into a file")
510                 return 1
511             return self.copy_file_to_file(sources[0], target)
512
513         if isinstance(target, MissingTargets):
514             if recursive:
515                 return self.copy_to_directory(sources, target)
516             if len(sources) > 1:
517                 # if we have -r, we'll auto-create the target directory. Without
518                 # it, we'll only create a file.
519                 self.to_stderr("cannot copy multiple files into a file without -r")
520                 return 1
521             # cp file1 newfile
522             return self.copy_file_to_file(sources[0], target)
523
524         if isinstance(target, DirectoryTargets):
525             # We're copying to an existing directory -- make sure that we
526             # have target names for everything
527             for source in sources:
528                 if source.basename() is None and isinstance(source, TahoeFileSource):
529                     self.to_stderr(
530                         "error: you must specify a destination filename")
531                     return 1
532             return self.copy_to_directory(sources, target)
533
534         self.to_stderr("unknown target")
535         return 1
536
537     def to_stderr(self, text):
538         print >>self.stderr, text
539
540     # FIXME reduce the amount of near-duplicate code between get_target_info
541     # and get_source_info.
542
543     def get_target_info(self, destination_spec):
544         precondition(isinstance(destination_spec, unicode), destination_spec)
545         rootcap, path_utf8 = get_alias(self.aliases, destination_spec, None)
546         path = path_utf8.decode("utf-8")
547         if rootcap == DefaultAliasMarker:
548             # no alias, so this is a local file
549             pathname = abspath_expanduser_unicode(path)
550             if not os.path.exists(pathname):
551                 t = LocalMissingTarget(pathname)
552             elif os.path.isdir(pathname):
553                 t = LocalDirectoryTarget(self.progress, pathname)
554             else:
555                 # TODO: should this be _assert? what happens if the target is
556                 # a special file?
557                 assert os.path.isfile(pathname), pathname
558                 t = LocalFileTarget(pathname) # non-empty
559         else:
560             # this is a tahoe object
561             url = self.nodeurl + "uri/%s" % urllib.quote(rootcap)
562             if path:
563                 url += "/" + escape_path(path)
564
565             resp = do_http("GET", url + "?t=json")
566             if resp.status == 404:
567                 # doesn't exist yet
568                 t = TahoeMissingTarget(url)
569             elif resp.status == 200:
570                 parsed = simplejson.loads(resp.read())
571                 nodetype, d = parsed
572                 if nodetype == "dirnode":
573                     t = TahoeDirectoryTarget(self.nodeurl, self.cache,
574                                              self.progress)
575                     t.init_from_parsed(parsed)
576                 else:
577                     writecap = to_str(d.get("rw_uri"))
578                     readcap = to_str(d.get("ro_uri"))
579                     mutable = d.get("mutable", False)
580                     t = TahoeFileTarget(self.nodeurl, mutable,
581                                         writecap, readcap, url)
582             else:
583                 raise HTTPError("Error examining target %s"
584                                  % quote_output(destination_spec), resp)
585         return t
586
587     def get_source_info(self, source_spec):
588         precondition(isinstance(source_spec, unicode), source_spec)
589         rootcap, path_utf8 = get_alias(self.aliases, source_spec, None)
590         path = path_utf8.decode("utf-8")
591         if rootcap == DefaultAliasMarker:
592             # no alias, so this is a local file
593             pathname = abspath_expanduser_unicode(path)
594             name = os.path.basename(pathname)
595             if not os.path.exists(pathname):
596                 raise MissingSourceError(source_spec, quotefn=quote_local_unicode_path)
597             if os.path.isdir(pathname):
598                 t = LocalDirectorySource(self.progress, pathname, name)
599             else:
600                 assert os.path.isfile(pathname)
601                 t = LocalFileSource(pathname, name) # non-empty
602         else:
603             # this is a tahoe object
604             url = self.nodeurl + "uri/%s" % urllib.quote(rootcap)
605             name = None
606             if path:
607                 url += "/" + escape_path(path)
608                 last_slash = path.rfind(u"/")
609                 name = path
610                 if last_slash != -1:
611                     name = path[last_slash+1:]
612
613             resp = do_http("GET", url + "?t=json")
614             if resp.status == 404:
615                 raise MissingSourceError(source_spec)
616             elif resp.status != 200:
617                 raise HTTPError("Error examining source %s" % quote_output(source_spec),
618                                 resp)
619             parsed = simplejson.loads(resp.read())
620             nodetype, d = parsed
621             if nodetype == "dirnode":
622                 t = TahoeDirectorySource(self.nodeurl, self.cache,
623                                          self.progress, name)
624                 t.init_from_parsed(parsed)
625             else:
626                 writecap = to_str(d.get("rw_uri"))
627                 readcap = to_str(d.get("ro_uri"))
628                 mutable = d.get("mutable", False) # older nodes don't provide it
629
630                 last_slash = source_spec.rfind(u"/")
631                 if last_slash != -1:
632                     # TODO: this looks funny and redundant with the 'name'
633                     # assignment above. cf #2329
634                     name = source_spec[last_slash+1:]
635
636                 t = TahoeFileSource(self.nodeurl, mutable, writecap, readcap, name)
637         return t
638
639
640     def need_to_copy_bytes(self, source, target):
641         if source.need_to_copy_bytes:
642             # mutable tahoe files, and local files
643             return True
644         if isinstance(target, (LocalFileTarget, LocalDirectoryTarget)):
645             return True
646         return False
647
648     def announce_success(self, msg):
649         if self.verbosity >= 1:
650             print >>self.stdout, "Success: %s" % msg
651         return 0
652
653     def copy_file_to_file(self, source, target):
654         precondition(isinstance(source, FileSources), source)
655         precondition(isinstance(target, FileTargets + MissingTargets), target)
656         if self.need_to_copy_bytes(source, target):
657             # if the target is a local directory, this will just write the
658             # bytes to disk. If it is a tahoe directory, it will upload the
659             # data, and stash the new filecap for a later set_children call.
660             f = source.open(self.caps_only)
661             target.put_file(f)
662             return self.announce_success("file copied")
663         # otherwise we're copying tahoe to tahoe, and using immutable files,
664         # so we can just make a link. TODO: this probably won't always work:
665         # need to enumerate the cases and analyze them.
666         target.put_uri(source.bestcap())
667         return self.announce_success("file linked")
668
669     def copy_file_into_dir(self, source, name, target):
670         precondition(isinstance(source, FileSources), source)
671         precondition(isinstance(target, DirectoryTargets), target)
672         precondition(isinstance(name, unicode), name)
673         if self.need_to_copy_bytes(source, target):
674             # if the target is a local directory, this will just write the
675             # bytes to disk. If it is a tahoe directory, it will upload the
676             # data, and stash the new filecap for a later set_children call.
677             f = source.open(self.caps_only)
678             target.put_file(name, f)
679             return
680         # otherwise we're copying tahoe to tahoe, and using immutable files,
681         # so we can just make a link
682         target.put_uri(name, source.bestcap())
683
684
685     def progress(self, message):
686         #print message
687         if self.progressfunc:
688             self.progressfunc(message)
689
690
691 def copy(options):
692     return Copier().do_copy(options)
693
694 # error cases that need improvement:
695 #  local-file-in-the-way
696 #   touch proposed
697 #   tahoe cp -r my:docs/proposed/denver.txt proposed/denver.txt
698 #  handling of unknown nodes
699
700 # things that maybe should be errors but aren't
701 #  local-dir-in-the-way
702 #   mkdir denver.txt
703 #   tahoe cp -r my:docs/proposed/denver.txt denver.txt
704 #   (creates denver.txt/denver.txt)
705
706 # error cases that look good:
707 #  tahoe cp -r my:docs/missing missing
708 #  disconnect servers
709 #   tahoe cp -r my:docs/missing missing  -> No JSON object could be decoded
710 #  tahoe-file-in-the-way (when we want to make a directory)
711 #   tahoe put README my:docs
712 #   tahoe cp -r docs/proposed my:docs/proposed