Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
export: Use tar -C to switch directories.
Anders Kaseorg27977eddeb9b
diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex 2449fb27820..aaa8e9af4cb 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -1874,14 +1874,15 @@ def do_export_realm(do_write_stats_file_for_realm_export(output_dir)- # We need to change back to the current working directory after writing- # the tarball to the output directory, otherwise the state is compromised- # for our unit tests.- reset_dir = os.getcwd()tarball_path = output_dir.rstrip("/") + ".tar.gz"- os.chdir(os.path.dirname(output_dir))- subprocess.check_call(["tar", "-czf", tarball_path, os.path.basename(output_dir)])- os.chdir(reset_dir)+ subprocess.check_call(+ [+ "tar",+ f"-czf{tarball_path}",+ f"-C{os.path.dirname(output_dir)}",+ os.path.basename(output_dir),+ ]+ )return tarball_pathdiff --git a/zerver/management/commands/export_single_user.py b/zerver/management/commands/export_single_user.pyindex 25fca88e3b4..61b5203d40d 100644--- a/zerver/management/commands/export_single_user.py+++ b/zerver/management/commands/export_single_user.py@@ -46,7 +46,12 @@ class Command(ZulipBaseCommand):do_export_user(user_profile, output_dir)print(f"Finished exporting to {output_dir}; tarring")tarball_path = output_dir.rstrip("/") + ".tar.gz"-- os.chdir(os.path.dirname(output_dir))- subprocess.check_call(["tar", "-czf", tarball_path, os.path.basename(output_dir)])+ subprocess.check_call(+ [+ "tar",+ f"-czf{tarball_path}",+ f"-C{os.path.dirname(output_dir)}",+ os.path.basename(output_dir),+ ]+ )print(f"Tarball written to {tarball_path}")