From d66967f851374a2882ec79ec2d56a7338a7ed534 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 13 Aug 2018 13:30:43 -0700 Subject: [PATCH] import: Use os.path.expanduser when accessing paths. This fixes an issue where passing a path like `~/exports/foo` would result in a `~` directory being created and the export/import not working correctly. --- zerver/management/commands/export.py | 2 +- zerver/management/commands/import.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/zerver/management/commands/export.py b/zerver/management/commands/export.py index f2606725ff..2e953b7aa1 100644 --- a/zerver/management/commands/export.py +++ b/zerver/management/commands/export.py @@ -107,7 +107,7 @@ class Command(ZulipBaseCommand): if output_dir is None: output_dir = tempfile.mkdtemp(prefix="/tmp/zulip-export-") else: - output_dir = os.path.realpath(output_dir) + output_dir = os.path.realpath(os.path.expanduser(output_dir)) if os.path.exists(output_dir): shutil.rmtree(output_dir) os.makedirs(output_dir) diff --git a/zerver/management/commands/import.py b/zerver/management/commands/import.py index 8678a9e90f..c84f6fc9d4 100644 --- a/zerver/management/commands/import.py +++ b/zerver/management/commands/import.py @@ -55,15 +55,18 @@ import a database dump from one or more JSON files.""" check_subdomain_available(subdomain, from_management_command=True) + paths = [] for path in options['export_paths']: + path = os.path.realpath(os.path.expanduser(path)) if not os.path.exists(path): print("Directory not found: '%s'" % (path,)) exit(1) if not os.path.isdir(path): print("Export file should be folder; if it's a tarball, please unpack it first.") exit(1) + paths.append(path) - for path in options['export_paths']: + for path in paths: print("Processing dump: %s ..." % (path,)) realm = do_import_realm(path, subdomain) print("Checking the system bots.")