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(duckdb): replace empty placeholder database files
hb074cef83583f
diff --git a/crates/dbx-core/src/connection.rs b/crates/dbx-core/src/connection.rsindex b4584d8c49..bdc5f458e6 100644--- a/crates/dbx-core/src/connection.rs+++ b/crates/dbx-core/src/connection.rs@@ -3377,6 +3377,7 @@ mod tests {async fn duckdb_client_session_reuses_base_pool_to_avoid_file_locks() {let (state, dir) = test_app_state().await;let db_path = dir.join("session.duckdb");+ duckdb::Connection::open(&db_path).unwrap();let mut config = mysql_config(None);config.id = "duckdb-conn".to_string();config.name = "DuckDB".to_string();diff --git a/crates/dbx-core/src/db/duckdb_driver.rs b/crates/dbx-core/src/db/duckdb_driver.rsindex d64ee97519..ad7cf93942 100644--- a/crates/dbx-core/src/db/duckdb_driver.rs+++ b/crates/dbx-core/src/db/duckdb_driver.rs@@ -1,5 +1,6 @@#![cfg(feature = "duckdb-bundled")]+use std::fs;use std::path::Path;use std::sync::Arc;use std::sync::Mutex;@@ -16,6 +17,7 @@ pub fn connect_path(path: &str) -> Result<Arc<Mutex<duckdb::Connection>>, Stringlet is_memory = is_memory_database_path(path);if !is_memory {validate_duckdb_path(path)?;+ remove_empty_placeholder_file(path)?;}let connection = if is_memory { duckdb::Connection::open_in_memory() } else { duckdb::Connection::open(path) }@@ -50,6 +52,19 @@ fn validate_duckdb_path(path: &str) -> Result<(), String> {Ok(())}+fn remove_empty_placeholder_file(path: &str) -> Result<(), String> {+ let path_obj = Path::new(path);+ if is_network_path(path) || !path_obj.exists() {+ return Ok(());+ }++ let metadata = fs::metadata(path_obj).map_err(|e| format!("Failed to read database file metadata: {e}"))?;+ if metadata.is_file() && metadata.len() == 0 {+ fs::remove_file(path_obj).map_err(|e| format!("Failed to replace empty DuckDB placeholder file: {e}"))?;+ }+ Ok(())+}+fn is_network_path(path: &str) -> bool {path.starts_with("\\\\") || path.starts_with("//") || path.contains("wsl.localhost") || path.contains("wsl$")}@@ -94,4 +109,17 @@ mod tests {assert_eq!(value, 42);}++ #[test]+ fn connect_path_replaces_empty_placeholder_file() {+ let path = std::env::temp_dir().join(format!("dbx-duckdb-empty-{}.duckdb", uuid::Uuid::new_v4()));+ std::fs::write(&path, "").expect("write empty placeholder");+ assert_eq!(std::fs::metadata(&path).expect("placeholder metadata").len(), 0);++ let con = connect_path(path.to_string_lossy().as_ref()).expect("connect empty placeholder DuckDB file");+ close_connection(con);++ assert!(std::fs::metadata(&path).expect("database metadata").len() > 0);+ let _ = std::fs::remove_file(path);+ }}