]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/scripts/magic_folder_cli.py
Prevent magic-folder join if already joined.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / magic_folder_cli.py
index 37aeec76a59446893bb7e327f4b2545729b85819..245a9b6a6e42884ca7cbf98c14d3abf6a33ae036 100644 (file)
@@ -27,10 +27,13 @@ class CreateOptions(BasedirOptions):
             raise usage.UsageError("An alias must end with a ':' character.")
         self.alias = alias[:-1]
         self.nickname = None if nickname is None else argv_to_unicode(nickname)
-        self.local_dir = None if local_dir is None else argv_to_abspath(local_dir)
+
+        # Expand the path relative to the current directory of the CLI command, not the node.
+        self.local_dir = None if local_dir is None else argv_to_abspath(local_dir, long_path=False)
+
         if self.nickname and not self.local_dir:
             raise usage.UsageError("If NICKNAME is specified then LOCAL_DIR must also be specified.")
-        node_url_file = os.path.join(self['node-directory'], "node.url")
+        node_url_file = os.path.join(self['node-directory'], u"node.url")
         self['node-url'] = fileutil.read(node_url_file).strip()
 
 def _delegate_options(source_options, target_options):
@@ -88,7 +91,7 @@ class InviteOptions(BasedirOptions):
             raise usage.UsageError("An alias must end with a ':' character.")
         self.alias = alias[:-1]
         self.nickname = argv_to_unicode(nickname)
-        node_url_file = os.path.join(self['node-directory'], "node.url")
+        node_url_file = os.path.join(self['node-directory'], u"node.url")
         self['node-url'] = open(node_url_file, "r").read().strip()
         aliases = get_aliases(self['node-directory'])
         self.aliases = aliases
@@ -136,7 +139,9 @@ class JoinOptions(BasedirOptions):
     magic_readonly_cap = ""
     def parseArgs(self, invite_code, local_dir):
         BasedirOptions.parseArgs(self)
-        self.local_dir = None if local_dir is None else argv_to_abspath(local_dir)
+
+        # Expand the path relative to the current directory of the CLI command, not the node.
+        self.local_dir = None if local_dir is None else argv_to_abspath(local_dir, long_path=False)
         self.invite_code = to_str(argv_to_unicode(invite_code))
 
 def join(options):
@@ -148,8 +153,13 @@ def join(options):
     dmd_cap_file = os.path.join(options["node-directory"], u"private", u"magic_folder_dircap")
     collective_readcap_file = os.path.join(options["node-directory"], u"private", u"collective_dircap")
 
+    if os.path.exists(dmd_cap_file) or os.path.exists(collective_readcap_file):
+        raise usage.UsageError("Cannot join. Already joined.")
+
     fileutil.write(dmd_cap_file, dmd_write_cap)
     fileutil.write(collective_readcap_file, magic_readonly_cap)
+
+    # FIXME: modify any existing [magic_folder] fields, rather than appending.
     fileutil.write(os.path.join(options["node-directory"], u"tahoe.cfg"),
                    "[magic_folder]\nenabled = True\nlocal.directory = %s\n"
                    % (options.local_dir.encode('utf-8'),), mode="ab")