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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(mcp): clear readonly attribute on replacement temp cleanup
caiyq925-cell0566e0db0c7a
diff --git a/.github/scripts/install-mcp-powershell.test.ps1 b/.github/scripts/install-mcp-powershell.test.ps1index 32c269006c..5c0f9c65c3 100644--- a/.github/scripts/install-mcp-powershell.test.ps1+++ b/.github/scripts/install-mcp-powershell.test.ps1@@ -134,6 +134,13 @@ try {Remove-McpReplacementTempFiles (Join-Path $testRoot 'missing')$script:count++Write-Output 'PASS cleanup preserves active binary, marker, unrelated files and directories'+ $readonlyPath = Join-Path $installDir 'dbx-mcp.exe~RF8c73e4f.TMP'+ [IO.File]::WriteAllText($readonlyPath, 'readonly leftover')+ [IO.File]::SetAttributes($readonlyPath, [IO.FileAttributes]::ReadOnly)+ Remove-McpReplacementTempFiles $installDir+ Assert-True (!(Test-Path -LiteralPath $readonlyPath)) 'Cleanup kept a read-only replacement temp file'+ $script:count+++ Write-Output 'PASS cleanup removes read-only replacement temp files'$linkTarget = Join-Path $testRoot 'linked-target'[IO.Directory]::CreateDirectory($linkTarget) | Out-Null$targetFile = Join-Path $linkTarget 'dbx-mcp.exe~RF789.TMP'diff --git a/docs/public/install-mcp.ps1 b/docs/public/install-mcp.ps1index 4ef3bff47d..29cf6176e3 100644--- a/docs/public/install-mcp.ps1+++ b/docs/public/install-mcp.ps1@@ -50,6 +50,9 @@ function Remove-McpReplacementTempFiles([string]$Directory) {$_.Name -imatch '\Adbx-mcp\.exe~RF[0-9a-f]+\.TMP\z'} | ForEach-Object {# A running MCP process may still hold the old executable; retry on the next run.+ # A READONLY attribute makes [IO.File]::Delete throw, so one read-only+ # leftover would otherwise survive every install; clear it first.+ try { $_.Attributes = $_.Attributes -band (-bnot [IO.FileAttributes]::ReadOnly) } catch {}try { [IO.File]::Delete($_.FullName) } catch {}}} catch {}diff --git a/src-tauri/src/commands/mcp_cleanup.rs b/src-tauri/src/commands/mcp_cleanup.rsindex a3d0e40fd8..d27029d364 100644--- a/src-tauri/src/commands/mcp_cleanup.rs+++ b/src-tauri/src/commands/mcp_cleanup.rs@@ -39,8 +39,24 @@ pub(super) fn cleanup_directory(directory: &Path) -> io::Result<usize> {}let path = entry.path();let Ok(metadata) = fs::symlink_metadata(&path) else { continue };- // Never recurse or follow links; locked/read-only leftovers can be retried next launch.- if metadata.is_file() && !is_link(&metadata) && fs::remove_file(&path).is_ok() {+ // Never recurse or follow links; locked leftovers can be retried next launch.+ if !metadata.is_file() || is_link(&metadata) {+ continue;+ }+ // A READONLY attribute makes fs::remove_file fail with Access Denied on+ // Windows, so one read-only leftover would otherwise survive every+ // startup pass. Clear the attribute (the name pattern is strict enough)+ // before deleting. This is Windows-only: on Unix unlinking only needs a+ // writable directory, and clearing the write bits would widen the mode+ // to 0666 if the delete failed. The clear is best-effort so a failed+ // attribute write never skips the delete attempt.+ #[cfg(windows)]+ if metadata.permissions().readonly() {+ let mut permissions = metadata.permissions();+ permissions.set_readonly(false);+ let _ = fs::set_permissions(&path, permissions);+ }+ if fs::remove_file(&path).is_ok() {removed += 1;}}@@ -124,6 +140,20 @@ mod tests {assert!(!missing.exists());}+ #[test]+ fn removes_read_only_leftovers() {+ let directory = TestDirectory::new();+ let readonly_path = directory.0.join("dbx-mcp.exe~RF8c73e4f.TMP");+ fs::write(&readonly_path, b"readonly leftover").unwrap();+ let mut permissions = fs::metadata(&readonly_path).unwrap().permissions();+ permissions.set_readonly(true);+ fs::set_permissions(&readonly_path, permissions).unwrap();+ assert!(fs::metadata(&readonly_path).unwrap().permissions().readonly());++ assert_eq!(cleanup_directory(&directory.0).unwrap(), 1);+ assert!(!readonly_path.exists());+ }+#[cfg(unix)]#[test]fn skips_symlinked_files_and_directories() {