Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(update_cache): clear existing ready dir before rename on Windows

dadong37fc2f8a9bb3
diff --git a/src-tauri/src/commands/update_cache.rs b/src-tauri/src/commands/update_cache.rs
index f2512c16f9..1aa42c9afe 100644
--- a/src-tauri/src/commands/update_cache.rs
+++ b/src-tauri/src/commands/update_cache.rs
@@ -63,6 +63,10 @@ pub(super) fn commit(root: &Path, record: &CacheRecord, bytes: &[u8]) -> Result<
#[cfg(unix)]
fs::File::open(&staging).and_then(|dir| dir.sync_all()).map_err(|e| e.to_string())?;
let ready = root.join("ready");
+ // Windows cannot rename onto an existing directory: `fs::rename` fails with
+ // `os error 5` when `ready` is still present from an earlier attempt. Clear
+ // it first so the commit is idempotent and does not need a manual retry.
+ discard(root)?;
fs::rename(&staging, &ready)
.map_err(|error| context("Failed to finalize the DBX update cache", &ready, error))?;
#[cfg(unix)]
@@ -215,6 +219,38 @@ mod tests {
fs::remove_dir_all(root).unwrap();
}
+ // A leftover `ready` from an earlier attempt is invisible to `ensure_writable`,
+ // yet Windows cannot rename onto an existing directory, so commit must clear it.
+ #[test]
+ fn commit_replaces_a_leftover_ready_directory_without_a_manual_retry() {
+ let root = std::env::temp_dir().join(uuid::Uuid::new_v4().to_string());
+ let stale = root.join("ready");
+ fs::create_dir_all(&stale).unwrap();
+ fs::write(stale.join("package"), b"previous attempt").unwrap();
+ let record = CacheRecord {
+ schema_version: 1,
+ package_kind: "test".into(),
+ package_length: 7,
+ package_sha256: digest(b"payload"),
+ info: DownloadedUpdate {
+ cache_id: "test".into(),
+ version: "99.0.0".into(),
+ portable_mode: false,
+ release_url: String::new(),
+ release_notes: String::new(),
+ downloaded_at: 1,
+ },
+ os: std::env::consts::OS.into(),
+ arch: std::env::consts::ARCH.into(),
+ manifest: None,
+ signature: None,
+ };
+ commit(&root, &record, b"payload").unwrap();
+ assert_eq!(read(&root).unwrap().unwrap().1, b"payload");
+ assert_eq!(fs::read(stale.join("package")).unwrap(), b"payload");
+ fs::remove_dir_all(root).unwrap();
+ }
+
#[test]
fn incomplete_writes_are_invisible_and_commit_roundtrips() {
let root = std::env::temp_dir().join(uuid::Uuid::new_v4().to_string());
@@ -240,7 +276,7 @@ mod tests {
};
commit(&root, &record, b"signed payload").unwrap();
assert_eq!(read(&root).unwrap().unwrap().1, b"signed payload");
- assert!(commit(&root, &record, b"replacement").is_err());
+ commit(&root, &record, b"replacement").unwrap();
fs::write(root.join("ready/package"), b"changed payload").unwrap();
assert!(read(&root).unwrap_err().contains("corrupt"));
fs::write(root.join("ready/package"), b"signed payload").unwrap();