Files
mtgc/crates/mtgc-core/src/bin/ingest.rs
Garrett Mills c527e5d6f7 Card data update: release reference.db before replacing it
Windows refuses to replace a file SQLite has open, so every update after the first failed at the final swap with "Access is denied". Building and installing are now separate: the app stays usable during the build, then closes the catalog, swaps the file and reopens under the state lock. The swap retries briefly in case a virus scanner is holding the new file, and a failed one puts the previous data back in service and removes the temp file. Importing a card database shares the same swap.
2026-10-30 20:15:34 -05:00

39 lines
1.1 KiB
Rust

//! CLI: build reference.db from Scryfall bulk data.
//!
//! Usage: `mtgc-ingest [path/to/reference.db]` (defaults to ./reference.db)
use std::path::PathBuf;
use std::process::ExitCode;
use mtgc_core::ingest::CancelToken;
fn main() -> ExitCode {
let dest = std::env::args()
.nth(1)
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("reference.db"));
eprintln!("Building reference db at {}", dest.display());
let cancel = CancelToken::new();
let built = mtgc_core::ingest::build_reference_db(&dest, &cancel, |p| {
eprintln!(" [{}] {:.1}% {}", p.stage, p.overall_percent, p.message)
})
.and_then(|(tmp, stats)| {
mtgc_core::ingest::install_reference_db(&tmp, &dest)?;
Ok(stats)
});
match built {
Ok(stats) => {
eprintln!(
"Done: {} oracle cards, {} printings.",
stats.oracle_cards, stats.printings
);
ExitCode::SUCCESS
}
Err(e) => {
eprintln!("Ingest failed: {e}");
ExitCode::FAILURE
}
}
}