From d0abb72abae0942a3e8fd7ba45b7ed51c359979b Mon Sep 17 00:00:00 2001 From: 4aiman Date: Mon, 21 Sep 2026 13:22:05 +0300 Subject: [PATCH] DB backup: use native_root() for the app root (not app_data_dir parent chain) - the fix we already made for point files --- src-tauri/src/lib.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8eb1af7..d864428 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -624,18 +624,14 @@ fn read_file_base64(path: String) -> Result { Ok(base64::engine::general_purpose::STANDARD.encode(&bytes)) } -// Resolve the main baldav.db path (same fallbacks as rebuild_roads/get_road_points) and the -// app root = the DIRECTORY that holds baldav.db. Deriving root from data_dir/../.. is wrong: -// app_data_dir() on Android is sometimes already the app root, so ../.. lands in /data/user -// (not writable) — measured, VACUUM INTO failed there. The dir next to baldav.db is always -// writable and is exactly what Kotlin (filesDir.parentFile) watches/reads. +// App root (holds baldav.db + point files + the command files Kotlin watches) and the DB path. +// MUST use native_root(): app_data_dir() nesting on Android is unreliable, so any ad-hoc +// app_data_dir().parent().parent() / db.parent() is wrong (measured: it lands in the +// unwritable /data/user and VACUUM INTO fails). native_root() scans candidates and returns the +// real writable app root that Kotlin's filesDir.parentFile also uses. Same as save points do. fn db_and_root(app: &tauri::AppHandle) -> Result<(std::path::PathBuf, std::path::PathBuf), String> { - let data_dir = app.path().app_data_dir().map_err(|e| e.to_string())?; - let p1 = data_dir.join("../../baldav.db"); - let p2 = data_dir.join("baldav.db"); - let p3 = std::path::PathBuf::from(data_dir.to_str().unwrap_or("").replace("/files/dev.baldav.app", "")).join("baldav.db"); - let db = if p1.exists() { p1 } else if p2.exists() { p2 } else { p3 }; - let root = db.parent().map(|p| p.to_path_buf()).unwrap_or(data_dir.clone()); + let root = native_root(app); + let db = root.join("baldav.db"); Ok((db, root)) }