File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,20 +12,31 @@ pub struct Database {
1212
1313impl 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 }
You can’t perform that action at this time.
0 commit comments