Skip to content

Commit 10894b4

Browse files
committed
fix: macOS config dir mismatch
1 parent 3577751 commit 10894b4

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

tui-rs/src/db/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,31 @@ pub struct Database {
1212

1313
impl Database {
1414
/// Open database at the given path, enabling WAL mode and foreign keys.
15+
/// Creates the parent directory if it does not exist.
1516
pub fn open(path: &PathBuf) -> Result<Self> {
17+
if let Some(parent) = path.parent() {
18+
std::fs::create_dir_all(parent).map_err(|e| {
19+
rusqlite::Error::SqliteFailure(
20+
rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_CANTOPEN),
21+
Some(format!("failed to create directory {}: {e}", parent.display())),
22+
)
23+
})?;
24+
}
1625
let conn = Connection::open(path)?;
1726
conn.execute_batch("PRAGMA foreign_keys = ON; PRAGMA journal_mode = WAL;")?;
1827
Ok(Self { conn })
1928
}
2029

2130
/// Return the default database path.
2231
/// Checks AXP_DB env var first, then ~/.config/arxiv-explorer/explorer.db
32+
/// Uses ~/.config/ explicitly (not dirs::config_dir) to stay consistent
33+
/// with the Python side on all platforms including macOS.
2334
pub fn default_path() -> PathBuf {
2435
if let Ok(p) = std::env::var("AXP_DB") {
2536
return PathBuf::from(p);
2637
}
27-
dirs::config_dir()
28-
.unwrap_or_else(|| PathBuf::from("."))
38+
let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
39+
home.join(".config")
2940
.join("arxiv-explorer")
3041
.join("explorer.db")
3142
}

0 commit comments

Comments
 (0)