mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-08 23:28:44 +00:00
Merge pull request #49 from PR0M3TH3AN/codex/fix-failing-workflow-tests
Fix restore with backup ID
This commit is contained in:
@@ -52,15 +52,16 @@ fn main() -> Result<()> {
|
||||
/* ── open DB (runs migrations) ───────────────────────────── */
|
||||
let mut conn = db::open(&cfg.db_path)?;
|
||||
|
||||
/* ── command dispatch ────────────────────────────────────── */
|
||||
match args.command {
|
||||
/* ── command dispatch ────────────────────────────────────── */
|
||||
match args.command {
|
||||
Commands::Completions { .. } => {} // handled above
|
||||
|
||||
/* ---- init ------------------------------------------------ */
|
||||
Commands::Init => {
|
||||
info!("Database initialised at {}", cfg.db_path.display());
|
||||
let cwd = env::current_dir().context("getting current directory")?;
|
||||
let count = scan::scan_directory(&mut conn, &cwd).context("initial scan failed")?;
|
||||
let count =
|
||||
scan::scan_directory(&mut conn, &cwd).context("initial scan failed")?;
|
||||
info!("Initial scan complete – indexed/updated {count} files");
|
||||
}
|
||||
|
||||
@@ -75,8 +76,11 @@ fn main() -> Result<()> {
|
||||
if dirty {
|
||||
let dirty_ids = take_dirty(&conn)?;
|
||||
for id in dirty_ids {
|
||||
let path: String =
|
||||
conn.query_row("SELECT path FROM files WHERE id = ?1", [id], |r| r.get(0))?;
|
||||
let path: String = conn.query_row(
|
||||
"SELECT path FROM files WHERE id = ?1",
|
||||
[id],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
scan::scan_directory(&mut conn, Path::new(&path))?;
|
||||
}
|
||||
} else {
|
||||
@@ -106,33 +110,38 @@ fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
Commands::Restore { backup_path } => {
|
||||
drop(conn);
|
||||
if backup_path.exists() { db::restore(&backup_path, &cfg.db_path)
|
||||
.with_context(|| {
|
||||
drop(conn); // close connection so the restore can overwrite the DB file
|
||||
|
||||
if backup_path.exists() {
|
||||
// User pointed to an actual backup file on disk
|
||||
db::restore(&backup_path, &cfg.db_path).with_context(|| {
|
||||
format!("Failed to restore DB from {}", backup_path.display())
|
||||
})?;
|
||||
} else {
|
||||
// Assume they passed just the file-name that lives in the standard backups dir
|
||||
let backups_dir = cfg.db_path.parent().unwrap().join("backups");
|
||||
let manager = BackupManager::new(&cfg.db_path, &backups_dir)?;
|
||||
|
||||
let name = backup_path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.context("invalid backup file name")?;
|
||||
manager
|
||||
.restore_from_backup(name)
|
||||
.with_context(|| {
|
||||
|
||||
manager.restore_from_backup(name).with_context(|| {
|
||||
format!("Failed to restore DB from {}", backup_path.display())
|
||||
})?;
|
||||
|
||||
}
|
||||
|
||||
println!("Restored DB from {}", backup_path.display());
|
||||
|
||||
// Re-open so the rest of the program talks to the fresh database
|
||||
db::open(&cfg.db_path).with_context(|| {
|
||||
format!("Could not open restored DB at {}", cfg.db_path.display())
|
||||
})?;
|
||||
info!("Successfully opened restored database.");
|
||||
}
|
||||
|
||||
/* ---- passthrough sub-modules (some still stubs) ---------- */
|
||||
/* ---- passthrough sub-modules ---------------------------- */
|
||||
Commands::Link(link_cmd) => cli::link::run(&link_cmd, &mut conn, args.format)?,
|
||||
Commands::Coll(coll_cmd) => cli::coll::run(&coll_cmd, &mut conn, args.format)?,
|
||||
Commands::View(view_cmd) => cli::view::run(&view_cmd, &mut conn, args.format)?,
|
||||
@@ -143,11 +152,10 @@ fn main() -> Result<()> {
|
||||
Commands::Version(v_cmd) => cli::version::run(&v_cmd, &mut conn, args.format)?,
|
||||
Commands::Event(e_cmd) => cli::event::run(&e_cmd, &mut conn, args.format)?,
|
||||
Commands::Watch(watch_cmd) => cli::watch::run(&watch_cmd, &mut conn, args.format)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
/* ─────────────────── helpers & sub-routines ─────────────────── */
|
||||
|
||||
/* ---------- TAGS ---------- */
|
||||
|
Reference in New Issue
Block a user