mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-09 07:38:50 +00:00
Merge branch 'beta' into codex/fix-failing-workflow-tests
This commit is contained in:
@@ -52,15 +52,16 @@ fn main() -> Result<()> {
|
|||||||
/* ── open DB (runs migrations) ───────────────────────────── */
|
/* ── open DB (runs migrations) ───────────────────────────── */
|
||||||
let mut conn = db::open(&cfg.db_path)?;
|
let mut conn = db::open(&cfg.db_path)?;
|
||||||
|
|
||||||
/* ── command dispatch ────────────────────────────────────── */
|
/* ── command dispatch ────────────────────────────────────── */
|
||||||
match args.command {
|
match args.command {
|
||||||
Commands::Completions { .. } => {} // handled above
|
Commands::Completions { .. } => {} // handled above
|
||||||
|
|
||||||
/* ---- init ------------------------------------------------ */
|
/* ---- init ------------------------------------------------ */
|
||||||
Commands::Init => {
|
Commands::Init => {
|
||||||
info!("Database initialised at {}", cfg.db_path.display());
|
info!("Database initialised at {}", cfg.db_path.display());
|
||||||
let cwd = env::current_dir().context("getting current directory")?;
|
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");
|
info!("Initial scan complete – indexed/updated {count} files");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +76,11 @@ fn main() -> Result<()> {
|
|||||||
if dirty {
|
if dirty {
|
||||||
let dirty_ids = take_dirty(&conn)?;
|
let dirty_ids = take_dirty(&conn)?;
|
||||||
for id in dirty_ids {
|
for id in dirty_ids {
|
||||||
let path: String =
|
let path: String = conn.query_row(
|
||||||
conn.query_row("SELECT path FROM files WHERE id = ?1", [id], |r| r.get(0))?;
|
"SELECT path FROM files WHERE id = ?1",
|
||||||
|
[id],
|
||||||
|
|r| r.get(0),
|
||||||
|
)?;
|
||||||
scan::scan_directory(&mut conn, Path::new(&path))?;
|
scan::scan_directory(&mut conn, Path::new(&path))?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -106,30 +110,38 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Commands::Restore { backup_path } => {
|
Commands::Restore { backup_path } => {
|
||||||
drop(conn);
|
drop(conn); // close connection so the restore can overwrite the DB file
|
||||||
|
|
||||||
if backup_path.exists() {
|
if backup_path.exists() {
|
||||||
|
// User pointed to an actual backup file on disk
|
||||||
db::restore(&backup_path, &cfg.db_path).with_context(|| {
|
db::restore(&backup_path, &cfg.db_path).with_context(|| {
|
||||||
format!("Failed to restore DB from {}", backup_path.display())
|
format!("Failed to restore DB from {}", backup_path.display())
|
||||||
})?;
|
})?;
|
||||||
} else {
|
} 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 backups_dir = cfg.db_path.parent().unwrap().join("backups");
|
||||||
let manager = BackupManager::new(&cfg.db_path, &backups_dir)?;
|
let manager = BackupManager::new(&cfg.db_path, &backups_dir)?;
|
||||||
|
|
||||||
let name = backup_path
|
let name = backup_path
|
||||||
.file_name()
|
.file_name()
|
||||||
.and_then(|n| n.to_str())
|
.and_then(|n| n.to_str())
|
||||||
.context("invalid backup file name")?;
|
.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())
|
format!("Failed to restore DB from {}", backup_path.display())
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Restored 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(|| {
|
db::open(&cfg.db_path).with_context(|| {
|
||||||
format!("Could not open restored DB at {}", cfg.db_path.display())
|
format!("Could not open restored DB at {}", cfg.db_path.display())
|
||||||
})?;
|
})?;
|
||||||
info!("Successfully opened restored database.");
|
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::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::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)?,
|
Commands::View(view_cmd) => cli::view::run(&view_cmd, &mut conn, args.format)?,
|
||||||
@@ -140,11 +152,10 @@ fn main() -> Result<()> {
|
|||||||
Commands::Version(v_cmd) => cli::version::run(&v_cmd, &mut conn, args.format)?,
|
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::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)?,
|
Commands::Watch(watch_cmd) => cli::watch::run(&watch_cmd, &mut conn, args.format)?,
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
|
||||||
/* ─────────────────── helpers & sub-routines ─────────────────── */
|
/* ─────────────────── helpers & sub-routines ─────────────────── */
|
||||||
|
|
||||||
/* ---------- TAGS ---------- */
|
/* ---------- TAGS ---------- */
|
||||||
|
Reference in New Issue
Block a user