DB backup: write export/staging next to baldav.db (app_data_dir can be the app root; ../.. hit unwritable /data/user)
This commit is contained in:
parent
263163cf52
commit
bb8a739b7e
1 changed files with 6 additions and 3 deletions
|
|
@ -625,14 +625,17 @@ fn read_file_base64(path: String) -> Result<String, String> {
|
|||
}
|
||||
|
||||
// Resolve the main baldav.db path (same fallbacks as rebuild_roads/get_road_points) and the
|
||||
// app root (where Kotlin's FileObserver watches). Root = data_dir/../.. on Android.
|
||||
// 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.
|
||||
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.clone() } else { p3 };
|
||||
let root = data_dir.parent().and_then(|p| p.parent()).map(|p| p.to_path_buf()).unwrap_or(data_dir.clone());
|
||||
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());
|
||||
Ok((db, root))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue