Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(bundle): 随包压缩包按指纹判定重新解压

hairyf984c37561493
diff --git a/src-tauri/resources/README.md b/src-tauri/resources/README.md
index 6a4ed141..c4968c4b 100644
--- a/src-tauri/resources/README.md
+++ b/src-tauri/resources/README.md
@@ -131,6 +131,14 @@ skips the download phase, reads the archive and feeds it through the ordinary ex
path (`download::ensure_extract` → `flatten_directory`), landing in the same app-data
managed roots a download would use.
+An upgrade replaces those archives but leaves the app-data trees in place, so each
+extraction also records a fingerprint of its archive (`<managed root>/.bundled-archive`,
+name + byte size) and a mismatching fingerprint makes the dependency count as *not*
+installed (see `config::dependencies::bundled_archive_is_stale`). A rebundled Node/pnpm/core
+is therefore unpacked once on the next launch, while an unchanged archive is not touched
+again. A core the user switched to a downloaded slot is exempt — re-unpacking the bundled
+archive there would overwrite the selected version.
+
Only what running `dsh` itself needs is bundled. Git is deliberately left out: it is not
required to start the harness, only git-backed features (worktree, `github:` plugins) are,
and an air-gapped machine can never provision it later. A bundled build therefore stops
diff --git a/src-tauri/src/config/dependencies.rs b/src-tauri/src/config/dependencies.rs
index 38f6f350..28c20a51 100644
--- a/src-tauri/src/config/dependencies.rs
+++ b/src-tauri/src/config/dependencies.rs
@@ -195,8 +195,8 @@ pub fn active_root<R: Runtime>(app: &AppHandle<R>, key: &str) -> PathBuf {
let resolved = manifest::resolve_location(app, &recorded.to_string_lossy());
// 安装目录里的记录同样不采信:旧离线包把依赖根写在那里,而现在解压产物
// 一律落在 AppData,老记录只会把应用钉在旧树上。
- let inside_install_dir = manifest::resource_root(app)
- .is_some_and(|root| resolved.starts_with(root));
+ let inside_install_dir =
+ manifest::resource_root(app).is_some_and(|root| resolved.starts_with(root));
if resolved.exists() && !inside_install_dir {
return resolved;
}
@@ -215,6 +215,53 @@ pub fn bundled_archive<R: Runtime>(app: &AppHandle<R>, key: &str) -> Option<Path
path.is_file().then_some(path)
}
+/// 托管根里记录「这份产物解压自哪个随包压缩包」的指纹文件。
+const BUNDLED_STAMP_FILE: &str = ".bundled-archive";
+
+/// 随包压缩包指纹:文件名 + 字节数。dsh 资产名不含版本(`deepseek-harness-pkg-*.zip`),
+/// 换版本只能靠体积区分;升级安装会把新压缩包同名覆盖,字节数随之改变。
+fn archive_fingerprint(archive: &Path) -> Option<String> {
+ let name = archive.file_name()?.to_string_lossy();
+ let size = std::fs::metadata(archive).ok()?.len();
+ Some(format!("{name}:{size}"))
+}
+
+/// 托管根与随包压缩包是否不同源(无记录、记录不匹配都算)。
+fn archive_stamp_differs(root: &Path, archive: &Path) -> bool {
+ let Some(fingerprint) = archive_fingerprint(archive) else {
+ return false;
+ };
+ std::fs::read_to_string(root.join(BUNDLED_STAMP_FILE))
+ .map(|recorded| recorded.trim() != fingerprint)
+ .unwrap_or(true)
+}
+
+fn write_archive_stamp(root: &Path, archive: &Path) {
+ let Some(fingerprint) = archive_fingerprint(archive) else {
+ return;
+ };
+ let _ = std::fs::create_dir_all(root);
+ let _ = std::fs::write(root.join(BUNDLED_STAMP_FILE), fingerprint);
+}
+
+/// 随包压缩包是否比托管根里的产物新(没有随包压缩包时恒为 false)。
+///
+/// 离线包升级会替换安装目录里的压缩包,而 AppData 里的解压产物留在原地:不比对指纹
+/// 就会一直用旧运行时。判定只在「托管根就是这份压缩包的解压目标」时有意义。
+pub fn bundled_archive_is_stale<R: Runtime>(app: &AppHandle<R>, key: &str) -> bool {
+ match bundled_archive(app, key) {
+ Some(archive) => archive_stamp_differs(&managed_root(app, key), &archive),
+ None => false,
+ }
+}
+
+/// 解压落盘后记录指纹:下次启动据此判定「随包压缩包已换新版」而重新解压。
+pub fn record_bundled_archive_stamp<R: Runtime>(app: &AppHandle<R>, key: &str) {
+ if let Some(archive) = bundled_archive(app, key) {
+ write_archive_stamp(&managed_root(app, key), &archive);
+ }
+}
+
/// 随包资源构建的随包核心根(普通安装为 None)。
///
/// 这类安装的运行时全部随安装包分发(见 `.github/actions/prepare-bundle-resources`),
@@ -413,4 +460,30 @@ mod tests {
);
}
}
+
+ #[test]
+ fn archive_stamp_detects_a_repacked_bundle() {
+ let dir = temp_path("stamp");
+ let root = dir.join("root");
+ let archive = dir.join("pnpm-11.7.0.tgz");
+ std::fs::create_dir_all(&dir).unwrap();
+ std::fs::write(&archive, b"first").unwrap();
+
+ // 没有指纹(首次安装)与换个压缩包都算「需要解压」
+ assert!(archive_stamp_differs(&root, &archive));
+ write_archive_stamp(&root, &archive);
+ assert!(!archive_stamp_differs(&root, &archive));
+
+ // 同名换版本:字节数变化即重新解压
+ std::fs::write(&archive, b"second-revision").unwrap();
+ assert!(archive_stamp_differs(&root, &archive));
+
+ // 文件名变化(dsh 之外的资产都带版本号)同样触发
+ let renamed = dir.join("pnpm-11.8.0.tgz");
+ std::fs::write(&renamed, b"second-revision").unwrap();
+ write_archive_stamp(&root, &archive);
+ assert!(archive_stamp_differs(&root, &renamed));
+
+ let _ = std::fs::remove_dir_all(dir);
+ }
}
diff --git a/src-tauri/src/config/runtime.rs b/src-tauri/src/config/runtime.rs
index 0c84cbaf..3b93bdb4 100644
--- a/src-tauri/src/config/runtime.rs
+++ b/src-tauri/src/config/runtime.rs
@@ -467,7 +467,9 @@ pub fn get_git_cmd_dir<R: Runtime>(_app_handle: &AppHandle<R>) -> Option<PathBuf
#[cfg(windows)]
pub fn git_runtime_ready<R: Runtime>(app_handle: &AppHandle<R>) -> bool {
find_system_git_binary().is_some()
- || git_binary_works(&get_mingit_binary_path(app_handle))
+ // 随包 MinGit 换新版后同样要重解压:旧产物的指纹对不上就当未安装。
+ || (git_binary_works(&get_mingit_binary_path(app_handle))
+ && !dependencies::bundled_archive_is_stale(app_handle, dependencies::DEP_GIT))
// 随包构建放宽只在「没有随包 MinGit 压缩包」时成立:真随包了 MinGit,
// 就必须让它走解压流程,否则放宽会把该任务跳过、Git 永远装不上。
|| (dependencies::bundled_core_dir(app_handle).is_some()
diff --git a/src-tauri/src/service/download/installable.rs b/src-tauri/src/service/download/installable.rs
index 9754469e..7a8ca6d2 100644
--- a/src-tauri/src/service/download/installable.rs
+++ b/src-tauri/src/service/download/installable.rs
@@ -81,7 +81,11 @@ impl Installable for Nodejs {
// 用那个 ABI 不匹配的运行时启动。
if config::prefer_bundled_node_runtime() {
return config::bundled_node_binary(app).is_some()
- && config::is_runtime_compatible(app);
+ && config::is_runtime_compatible(app)
+ && !config::dependencies::bundled_archive_is_stale(
+ app,
+ config::dependencies::DEP_NODE,
+ );
}
if let Some(local_node) = config::get_local_node_path() {
log::info!(
@@ -90,7 +94,9 @@ impl Installable for Nodejs {
);
return true;
}
- config::get_node_binary_path(app).exists() && config::is_runtime_compatible(app)
+ config::get_node_binary_path(app).exists()
+ && config::is_runtime_compatible(app)
+ && !config::dependencies::bundled_archive_is_stale(app, config::dependencies::DEP_NODE)
}
fn record_mapping(&self, app: &AppHandle) {
let managed = config::get_node_install_path(app);
@@ -123,7 +129,15 @@ impl Installable for Dsh {
config::get_dsh_install_path(app)
}
fn check_installed(&self, app: &AppHandle) -> bool {
- config::get_dsh_binary_path(app).exists()
+ if !config::get_dsh_binary_path(app).exists() {
+ return false;
+ }
+ // 随包压缩包解压出的托管根要跟随新版安装包(升级只替换压缩包,AppData 里的
+ // 解压产物留在原地)。只有生效根就是托管根时才让陈旧的压缩包判成待重装:用户
+ // 自选的下载槽位不在此列,否则重解压会覆盖用户选定的版本。
+ let active = config::dependencies::active_root(app, config::dependencies::DEP_DSH);
+ active != config::dependencies::managed_root(app, config::dependencies::DEP_DSH)
+ || !config::dependencies::bundled_archive_is_stale(app, config::dependencies::DEP_DSH)
}
fn record_mapping(&self, app: &AppHandle) {
// 记录**当前生效的根**而不是清单托管根:随包资源构建(离线包)里用户可以把内核
@@ -162,6 +176,7 @@ impl Installable for Pnpm {
return true;
}
config::get_pnpm_binary_path(app).exists()
+ && !config::dependencies::bundled_archive_is_stale(app, config::dependencies::DEP_PNPM)
}
fn record_mapping(&self, app: &AppHandle) {
let managed = config::get_pnpm_install_path(app);
diff --git a/src-tauri/src/service/workflow/install.rs b/src-tauri/src/service/workflow/install.rs
index 6ddf5192..d133ec7e 100644
--- a/src-tauri/src/service/workflow/install.rs
+++ b/src-tauri/src/service/workflow/install.rs
@@ -98,7 +98,8 @@ pub async fn install(
log::debug!("Processing task {}/{}", index + 1, tasks.len());
// 已安装但版本/commit 与最新 release 不一致时强制重新下载。
// 随包内核压缩包例外:本地压缩包就是权威版本,按 release 判定「过期」会把
- // 随包旧核心每次启动都重解压一遍。
+ // 随包旧核心每次启动都重解压一遍;安装包换了新版压缩包的情况由
+ // `bundled_archive_is_stale` 指纹判定(见 `Dsh::check_installed`)。
// 版本优先(与 resolve_update 的判定完全一致):dsh 的 rc 发布会复用
// 同一 git commit(record_commit 不变),只比 commit 会把 rc.8 之于
// rc.7 误判为"已最新"而跳过下载——日志表现为"All installation tasks
@@ -235,6 +236,10 @@ pub async fn install(
log::info!("Extraction completed");
// 解压落盘即建立该依赖的路径映射(新用户 / 缺少内核的场景)。
task.record_mapping(app_handle);
+ // 随包压缩包记指纹:安装包升级换了新版压缩包时,下次启动据此重解压。
+ if bundled.is_some() {
+ config::dependencies::record_bundled_archive_stamp(app_handle, kind.dependency_key());
+ }
tracker.end_phase();
// 记录本次安装对应的 release tag 与 commit,供下次启动比对