From: Daira Hopwood Date: Wed, 2 Dec 2015 15:54:01 +0000 (+0000) Subject: Improve the error reporting for 'tahoe magic-folder join/leave'. refs #2568 X-Git-Url: https://git.rkrishnan.org/pf/content/%22file:/CLI.txt?a=commitdiff_plain;h=6ca5fb36decde76798ab30cbe3b6a20aca4b05cc;p=tahoe-lafs%2Ftahoe-lafs.git Improve the error reporting for 'tahoe magic-folder join/leave'. refs #2568 Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/scripts/magic_folder_cli.py b/src/allmydata/scripts/magic_folder_cli.py index 1b7ff39a..e15176d1 100644 --- a/src/allmydata/scripts/magic_folder_cli.py +++ b/src/allmydata/scripts/magic_folder_cli.py @@ -10,7 +10,8 @@ from allmydata.util.assertutil import precondition from .common import BaseOptions, BasedirOptions, get_aliases from .cli import MakeDirectoryOptions, LnOptions, CreateAliasOptions import tahoe_mv -from allmydata.util.encodingutil import argv_to_abspath, argv_to_unicode, to_str +from allmydata.util.encodingutil import argv_to_abspath, argv_to_unicode, to_str, \ + quote_local_unicode_path from allmydata.util import fileutil from allmydata import uri @@ -155,7 +156,9 @@ def join(options): magic_folder_db_file = os.path.join(options["node-directory"], u"private", u"magicfolderdb.sqlite") if os.path.exists(dmd_cap_file) or os.path.exists(collective_readcap_file) or os.path.exists(magic_folder_db_file): - raise usage.UsageError("Cannot join. Already joined.") + print >>options.stderr, ("\nThis client has already joined a magic folder." + "\nUse the 'tahoe magic-folder leave' command first.\n") + return 1 fileutil.write(dmd_cap_file, dmd_write_cap) fileutil.write(collective_readcap_file, magic_readonly_cap) @@ -187,9 +190,11 @@ def leave(options): for f in [dmd_cap_file, collective_readcap_file, magic_folder_db_file]: try: - os.remove(f) - except OSError,e: - pass + fileutil.remove(f) + except Exception as e: + print >>options.stderr, ("Warning: unable to remove %s due to %s: %s" + % (quote_local_unicode_path(f), e.__class__.__name__, str(e))) + return 0 class MagicFolderCommand(BaseOptions):