DB backup: use native_root() for the app root (not app_data_dir parent chain) - the fix we already made for point files
This commit is contained in:
parent
5b3239258f
commit
d0abb72aba
1 changed files with 7 additions and 11 deletions
|
|
@ -624,18 +624,14 @@ fn read_file_base64(path: String) -> Result<String, String> {
|
|||
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))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue