diff options
Diffstat (limited to 'src/watch/mirror.rs')
| -rw-r--r-- | src/watch/mirror.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs index 5b7e2b1..0eb9a77 100644 --- a/src/watch/mirror.rs +++ b/src/watch/mirror.rs @@ -39,10 +39,7 @@ fn sync_mirror_impl(cfg: &Config, db: &Db, name: &str, url: &str) -> Result<Sync return Ok(Sync::Cloned { head }); } - let remote = match git::ls_remote_head(url)? { - Some(h) => h, - None => return Ok(Sync::Gone), - }; + let Some(remote) = git::ls_remote_head(url)? else { return Ok(Sync::Gone) }; let local = git::head(&mirror).ok(); if let Some(l) = &local { if *l == remote { @@ -95,9 +92,7 @@ pub(crate) fn read_tree(mirror: &Path, commit: &str) -> Result<Tree> { let contents = git::cat_file_batch(mirror, &oids)?; let mut files = BTreeMap::new(); for (path, sha) in &blobs { - let bytes = contents - .get(sha) - .ok_or_else(|| Error::not_found(Missing::MirrorPath(path.to_string())))?; + let bytes = contents.get(sha).ok_or_else(|| Error::not_found(Missing::MirrorPath(path.to_string())))?; if bytes.len() > 4 * 1024 * 1024 || !looks_textual(bytes) { continue; } @@ -114,7 +109,6 @@ pub(crate) fn read_file(mirror: &Path, commit: &str, path: &str) -> Result<Vec<u git::read_blob(mirror, commit, path) } - #[cfg(test)] mod tests { use super::*; @@ -125,10 +119,7 @@ mod tests { /// answer for, so the test does not stand up a mirror, a database or a /// config to ask it a question about one tree. fn repo(files: &[(&str, &[u8])]) -> (std::path::PathBuf, String) { - let nonce = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_nanos(); + let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(); let dir = std::env::temp_dir().join(format!("aur-read-tree-{}-{}", std::process::id(), nonce)); std::fs::create_dir_all(&dir).unwrap(); let git = |args: &[&str]| { @@ -157,10 +148,13 @@ mod tests { #[test] fn read_tree_returns_every_blob_from_one_batch_read() { let (dir, head) = repo(&[ - ("PKGBUILD", b"pkgbase=foo + ( + "PKGBUILD", + b"pkgbase=foo pkgver=1.0 pkgrel=1 -"), +", + ), ("empty.txt", b""), ("blob.bin", b"\x00not text"), ]); @@ -179,8 +173,11 @@ pkgrel=1 #[test] fn read_tree_fails_closed_when_the_commit_is_gone_from_the_mirror() { - let (dir, _head) = repo(&[("PKGBUILD", b"pkgbase=foo -")]); + let (dir, _head) = repo(&[( + "PKGBUILD", + b"pkgbase=foo +", + )]); for gone in ["0123456789012345678901234567890123456789", "deadbeef"] { let err = read_tree(&dir, gone).unwrap_err().to_string(); assert!(err.contains("missing from the local mirror"), "{gone}: {err}"); |
