summaryrefslogtreecommitdiffstats
path: root/src/watch/digests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/watch/digests.rs')
-rw-r--r--src/watch/digests.rs31
1 files changed, 6 insertions, 25 deletions
diff --git a/src/watch/digests.rs b/src/watch/digests.rs
index 07551ca..cb7bdbc 100644
--- a/src/watch/digests.rs
+++ b/src/watch/digests.rs
@@ -11,9 +11,8 @@
//! files are already in the mirror.
use crate::config::Config;
-use crate::db::*;
+use crate::db::{self, *};
use crate::error::Result;
-use crate::time;
use crate::watch::mirror::Tree;
const SKIP: &str = "SKIP";
@@ -144,37 +143,19 @@ pub fn download_and_cache(cfg: &Config, db: &Db, url: &str) -> Result<(String, u
} else {
let _ = std::fs::remove_file(&tmp);
}
- let at = time::now();
let dest_s = dest.display().to_string();
- let u = url.to_string();
- let digest_for_row = digest.clone();
- db.writer.tx(move |tx| {
- tx.execute(
- "INSERT INTO source_cache (url, digest, size, fetched_at, path) VALUES (?1,?2,?3,?4,?5)
- ON CONFLICT(url, digest) DO UPDATE SET fetched_at=excluded.fetched_at",
- rusqlite::params![u, digest_for_row, size as i64, at, dest_s],
- )?;
- Ok(())
- })?;
+ db::put_source_cache(&db.writer, url, &digest, size, &dest_s)?;
Ok((digest, size))
}
/// The cached file holding `digest`, if we still have it. The build uses this
/// so the bytes it consumes are the bytes that were hashed at detection time.
pub fn cached_path(db: &Db, url: &str, digest: &str) -> Option<std::path::PathBuf> {
- let p: Option<String> = db
- .read(|c| {
- use rusqlite::OptionalExtension;
- Ok(c.query_row(
- "SELECT path FROM source_cache WHERE url=?1 AND digest=?2",
- rusqlite::params![url, digest],
- |r| r.get(0),
- )
- .optional()?)
- })
+ db::source_cache_path(db, url, digest)
.ok()
- .flatten();
- p.map(std::path::PathBuf::from).filter(|p| p.exists())
+ .flatten()
+ .map(std::path::PathBuf::from)
+ .filter(|p| p.exists())
}
/// True when a `SKIP` on a non-VCS source means the recipe permanently refuses