From 1340f6c23301a939e231172a7b6e5ca9f5648e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Wed, 4 Nov 2026 15:47:21 +0800 Subject: [PATCH] build: stage immutable release files without duplicate copies --- packaging/SELF-EXTRACTING-RELEASE.md | 2 +- tests/packaging/test_self_extracting_release.py | 4 ++++ tools/build_self_extracting_release.py | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packaging/SELF-EXTRACTING-RELEASE.md b/packaging/SELF-EXTRACTING-RELEASE.md index 59cae16..5e38711 100644 --- a/packaging/SELF-EXTRACTING-RELEASE.md +++ b/packaging/SELF-EXTRACTING-RELEASE.md @@ -14,7 +14,7 @@ Extract the installer with an existing 7-Zip tool into a build-only directory. N python tools/build_self_extracting_release.py --source-dir dist/DxPartReplace --output-dir G:/dx-release-1.2.2 --version 1.2.2 --seven-zip build/7zip-2605/full/7z.exe --sfx-stub build/7zip-2605/full/7z.sfx --license build/7zip-2605/full/License.txt ``` -Use a fresh output directory. The tool rejects an existing directory, overlapping input/output paths and an application input containing `data`. It copies the complete input, includes the 7-Zip license, produces EXE + ZIP, and writes artifact and per-file SHA256 hashes. LZMA2 level 3 and bounded solid blocks keep decoding memory modest; tiny files still incur filesystem costs, so do not promise a fixed speedup across machines. +Use a fresh output directory and keep the completed build input unchanged during packaging. The tool rejects an existing directory, overlapping input/output paths and an application input containing `data`. It stages the complete input using same-volume hardlinks (copying when links are unavailable), includes the 7-Zip license, produces independent EXE + ZIP archives, and writes artifact and per-file SHA256 hashes. LZMA2 level 3 and bounded solid blocks keep decoding memory modest; tiny files still incur filesystem costs, so do not promise a fixed speedup across machines. Before publishing, run the self-extracting EXE itself with `-y -o`, compare every resulting file and every ZIP member against the manifest, and run `tools/verify_packaged_runtime.py` and Qt/DSH UI acceptance on that extracted EXE. Neither merely listing the archive nor the source UI tests replaces this check. diff --git a/tests/packaging/test_self_extracting_release.py b/tests/packaging/test_self_extracting_release.py index aec8fe4..52c4f2b 100644 --- a/tests/packaging/test_self_extracting_release.py +++ b/tests/packaging/test_self_extracting_release.py @@ -57,9 +57,13 @@ def test_actual_sfx_and_zip_extract_identical_unicode_and_empty_files(tmp_path): (source / '中文 目录').mkdir() (source / '中文 目录' / '空.txt').write_bytes(b'') (source / '中文 目录' / 'file.bin').write_bytes(bytes(range(256)) * 2048) + (source / 'licenses').mkdir() + original_license=source/'licenses'/'7-Zip-LICENSE.txt' + original_license.write_text('original input must remain unchanged') output = tmp_path / 'release' manifest = build_release(source, output, version='1.2.2', seven_zip=tools/'7z.exe', sfx_stub=tools/'7z.sfx', license_path=tools/'License.txt') + assert original_license.read_text() == 'original input must remain unchanged' destination = tmp_path / '解压 结果' result = verify(output/'release-manifest-1.2.2.json', destination) assert result['passed'] and result['files'] == 4 diff --git a/tools/build_self_extracting_release.py b/tools/build_self_extracting_release.py index ba99451..c8869fb 100644 --- a/tools/build_self_extracting_release.py +++ b/tools/build_self_extracting_release.py @@ -5,6 +5,7 @@ from __future__ import annotations import argparse import hashlib import json +import os import re from pathlib import Path import shutil @@ -32,6 +33,16 @@ def _zip_tree(source: Path, output: Path) -> int: return files +def _stage_file(source, destination): + # Release input is immutable during packaging. Same-volume links avoid a + # second copy of tens of thousands of runtime files; archives are independent. + try: + os.link(source, destination) + except OSError: + shutil.copyfile(source, destination) + return destination + + def build_release(source_dir: Path, output_dir: Path, *, version: str, seven_zip: Path, sfx_stub: Path, license_path: Path | None = None) -> dict: source_dir = Path(source_dir).resolve(strict=True) @@ -49,10 +60,12 @@ def build_release(source_dir: Path, output_dir: Path, *, version: str, seven_zip output_dir.mkdir(parents=True, exist_ok=False) staging = output_dir / "staging" / "DxPartReplace" - shutil.copytree(source_dir, staging) + shutil.copytree(source_dir, staging, copy_function=_stage_file) if license_path is not None: license_target = staging / "licenses" / "7-Zip-LICENSE.txt" license_target.parent.mkdir(parents=True, exist_ok=True) + # Break a possible staging hardlink before replacing a pre-existing notice. + license_target.unlink(missing_ok=True) shutil.copyfile(Path(license_path).resolve(strict=True), license_target) archive_7z = output_dir / f"DxPartReplace-{version}.7z"