From cf33119348325771b157c237c029e53c71cb880b Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 22 Aug 2025 18:32:19 +0000 Subject: [PATCH] export: Remove export-most-recent symlink. The only callsite of do_export_realm calls `rmtree` on the output path, which means this symlink is always dangling. Since realms can also be exported by end-users, following it would always be a race condition, anyways. Remove it. --- zerver/lib/export.py | 26 -------------------------- zerver/tests/test_import_export.py | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/zerver/lib/export.py b/zerver/lib/export.py index 28a98ffd50..e38395d1e8 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -16,7 +16,6 @@ import shutil import subprocess import tempfile from collections.abc import Callable, Iterable, Mapping -from contextlib import suppress from datetime import datetime from email.headerregistry import Address from functools import cache @@ -35,7 +34,6 @@ from psycopg2 import sql import zerver.lib.upload from analytics.models import RealmCount, StreamCount, UserCount -from scripts.lib.zulip_tools import overwrite_symlink from version import ZULIP_VERSION from zerver.lib.avatar_hash import user_avatar_base_path_from_ids from zerver.lib.migration_status import MigrationStatusJson, parse_migration_status @@ -2411,8 +2409,6 @@ def do_export_realm( realm_config = get_realm_config() - create_soft_link(source=output_dir, in_progress=True) - exportable_scheduled_message_ids = get_exportable_scheduled_message_ids( realm, export_type, exportable_user_ids ) @@ -2500,7 +2496,6 @@ def do_export_realm( do_common_export_processes(output_dir) logging.info("Finished exporting %s", realm.string_id) - create_soft_link(source=output_dir, in_progress=False) stats = do_write_stats_file_for_realm_export(output_dir) @@ -2532,27 +2527,6 @@ def export_attachment_table( return attachments -def create_soft_link(source: Path, in_progress: bool = True) -> None: - is_done = not in_progress - if settings.DEVELOPMENT: - in_progress_link = os.path.join(settings.DEPLOY_ROOT, "var", "export-in-progress") - done_link = os.path.join(settings.DEPLOY_ROOT, "var", "export-most-recent") - else: - in_progress_link = "/home/zulip/export-in-progress" - done_link = "/home/zulip/export-most-recent" - - if in_progress: - new_target = in_progress_link - else: - with suppress(FileNotFoundError): - os.remove(in_progress_link) - new_target = done_link - - overwrite_symlink(source, new_target) - if is_done: - logging.info("See %s for output files", new_target) - - def launch_user_message_subprocesses( threads: int, output_dir: Path, diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index 422522462d..472be41c14 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -412,7 +412,7 @@ class RealmImportExportTest(ExportFile): if export_type == RealmExport.EXPORT_FULL_WITH_CONSENT: assert exportable_user_ids is not None - with patch("zerver.lib.export.create_soft_link"), self.assertLogs(level="INFO"): + with self.assertLogs(level="INFO"): do_export_realm( realm=realm, output_dir=output_dir,