summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/review/approve.rs4
-rw-r--r--src/review/candidates.rs7
-rw-r--r--src/review/diff.rs7
-rw-r--r--src/review/risk.rs5
-rw-r--r--src/watch/digests.rs2
-rw-r--r--src/watch/mirror.rs87
-rw-r--r--src/watch/mod.rs5
-rw-r--r--src/watch/upstream.rs2
8 files changed, 83 insertions, 36 deletions
diff --git a/src/review/approve.rs b/src/review/approve.rs
index adc81c0..82812fb 100644
--- a/src/review/approve.rs
+++ b/src/review/approve.rs
@@ -220,7 +220,3 @@ pub fn withdraw(db: &Db, actor: &str, release_id: i64, reason: &str) -> Result<(
Ok(())
})
}
-
-pub fn current_accepted(db: &Db, pkgbase: &str) -> Result<Option<ReleaseRow>> {
- db::accepted_release(db, pkgbase)
-}
diff --git a/src/review/candidates.rs b/src/review/candidates.rs
index b220013..59db99b 100644
--- a/src/review/candidates.rs
+++ b/src/review/candidates.rs
@@ -6,13 +6,6 @@ pub use crate::db::candidates::{
reopen_rejected, set_diff_digest, NewCandidate,
};
-/// The risk columns are review's to write, from `intake::record` and nowhere
-/// else. A fixture that needs a particular score says so through this.
-#[cfg(feature = "test-support")]
-pub fn set_risk_for_tests(db: &Db, id: i64, level: &str, signals: &[String]) -> Result<()> {
- db::candidates::set_risk(db, id, level, signals)
-}
-
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Upsert {
Created { id: i64, kind: String },
diff --git a/src/review/diff.rs b/src/review/diff.rs
index 42467f0..4a8a3ef 100644
--- a/src/review/diff.rs
+++ b/src/review/diff.rs
@@ -266,13 +266,6 @@ pub fn diff_digest(ps: &[Panel]) -> String {
crate::hash::hex_str(&render_text(ps))
}
-pub fn full_recipe_text(db: &Db, c: &CandidateRow) -> Result<String> {
- let snap = db::snapshot_by_id(db, c.snapshot_id)?;
- let snap = snap.ok_or_else(|| crate::error::Error::not_found("snapshot missing"))?;
- let r: Recipe = serde_json::from_str(&snap.srcinfo_json).unwrap_or_default();
- Ok(r.pkgbuild)
-}
-
pub fn render_and_store(db: &Db, cfg: &Config, c: &CandidateRow) -> Result<String> {
let base = match c.base_release_id {
Some(id) => db::release_by_id(db, id)?,
diff --git a/src/review/risk.rs b/src/review/risk.rs
index 9c59bfa..9a7145d 100644
--- a/src/review/risk.rs
+++ b/src/review/risk.rs
@@ -16,15 +16,12 @@ const BUILD_SYSTEM_FILES: &[&str] = &[
];
#[derive(Debug, Clone, Default)]
-pub struct Assessment {
+pub(crate) struct Assessment {
pub level: String,
pub signals: Vec<String>,
}
impl Assessment {
- pub fn is_high(&self) -> bool {
- self.level == level::HIGH
- }
}
pub(crate) fn assess(
diff --git a/src/watch/digests.rs b/src/watch/digests.rs
index 534b5bd..027062b 100644
--- a/src/watch/digests.rs
+++ b/src/watch/digests.rs
@@ -4,7 +4,7 @@ use crate::error::Result;
use crate::recipe::{declared_sums, is_hex_digest, SKIP};
use crate::watch::mirror::Tree;
-pub fn resolve_sources(
+pub(crate) fn resolve_sources(
cfg: &Config,
db: &Db,
mirror: &std::path::Path,
diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs
index 924eb52..07a60c0 100644
--- a/src/watch/mirror.rs
+++ b/src/watch/mirror.rs
@@ -46,7 +46,7 @@ fn record(db: &Db, name: &str, head: &str, mirror: &Path) -> Result<()> {
}
#[derive(Debug, Clone)]
-pub struct Tree {
+pub(crate) struct Tree {
pub blobs: Vec<(String, String)>,
pub files: BTreeMap<String, String>,
}
@@ -55,18 +55,12 @@ impl Tree {
pub fn recipe_hash(&self) -> String {
crate::hash::recipe_hash(&self.blobs)
}
- pub fn get(&self, suffix: &str) -> Option<&String> {
- self.files
- .iter()
- .find(|(k, _)| k.ends_with(suffix))
- .map(|(_, v)| v)
- }
pub fn json_list(&self) -> String {
serde_json::to_string(&self.blobs).unwrap_or_else(|_| "[]".into())
}
}
-pub fn read_tree(mirror: &Path, commit: &str) -> Result<Tree> {
+pub(crate) fn read_tree(mirror: &Path, commit: &str) -> Result<Tree> {
// One `ls-tree` and one `cat-file --batch` for the whole tree, so the number
// of files a recipe ships does not decide how many processes a read costs.
// A commit that is gone from the mirror surfaces here, from `ls-tree`, rather
@@ -102,6 +96,81 @@ fn looks_textual(b: &[u8]) -> bool {
!b[..b.len().min(512)].contains(&0)
}
-pub fn read_file(mirror: &Path, commit: &str, path: &str) -> Result<Vec<u8>> {
+pub(crate) fn read_file(mirror: &Path, commit: &str, path: &str) -> Result<Vec<u8>> {
git::read_blob(mirror, commit, path)
}
+
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// A throwaway repo with these files committed, and its tip.
+ ///
+ /// Deliberately minimal: `read_tree` only ever needs a directory git will
+ /// 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 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]| {
+ let out = std::process::Command::new("git")
+ .arg("-C")
+ .arg(&dir)
+ .args(args)
+ .env("GIT_CONFIG_NOSYSTEM", "1")
+ .env("HOME", &dir)
+ .output()
+ .unwrap();
+ assert!(out.status.success(), "git {args:?}: {}", String::from_utf8_lossy(&out.stderr));
+ };
+ git(&["init", "-q", "-b", "master"]);
+ git(&["config", "user.email", "test@example.invalid"]);
+ git(&["config", "user.name", "test"]);
+ for (name, body) in files {
+ std::fs::write(dir.join(name), body).unwrap();
+ }
+ git(&["add", "-A"]);
+ git(&["commit", "-q", "-m", "initial"]);
+ let head = std::fs::read_to_string(dir.join(".git/refs/heads/master")).unwrap();
+ (dir, head.trim().to_string())
+ }
+
+ #[test]
+ fn read_tree_returns_every_blob_from_one_batch_read() {
+ let (dir, head) = repo(&[
+ ("PKGBUILD", b"pkgbase=foo
+pkgver=1.0
+pkgrel=1
+"),
+ ("empty.txt", b""),
+ ("blob.bin", b"\x00not text"),
+ ]);
+ let tree = read_tree(&dir, &head).unwrap();
+
+ assert!(tree.files["PKGBUILD"].contains("pkgver=1.0"));
+ assert_eq!(tree.files["empty.txt"], "", "an empty blob is a file, not a miss");
+ assert!(
+ !tree.files.contains_key("blob.bin"),
+ "a NUL in the first block means it is not text: {:?}",
+ tree.files.keys().collect::<Vec<_>>()
+ );
+ assert!(tree.blobs.iter().any(|(p, _)| p == "blob.bin"), "binary blobs are still listed");
+ std::fs::remove_dir_all(&dir).ok();
+ }
+
+ #[test]
+ fn read_tree_fails_closed_when_the_commit_is_gone_from_the_mirror() {
+ 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}");
+ }
+ std::fs::remove_dir_all(&dir).ok();
+ }
+}
diff --git a/src/watch/mod.rs b/src/watch/mod.rs
index b3c0533..839596a 100644
--- a/src/watch/mod.rs
+++ b/src/watch/mod.rs
@@ -6,7 +6,6 @@ pub mod sources;
pub mod staleness;
pub mod upstream;
-pub use detect::{check_pkgbase, CheckReport, Outcome};
-pub use digests::resolve_sources;
-pub use mirror::{read_tree, sync_mirror, Tree};
+pub use detect::{check_pkgbase, Outcome};
+pub use mirror::sync_mirror;
pub use scheduler::spawn_scheduler;
diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs
index 1af1488..002d72b 100644
--- a/src/watch/upstream.rs
+++ b/src/watch/upstream.rs
@@ -141,7 +141,7 @@ impl Drop for StageBSlot {
}
}
-pub fn resolve(
+pub(crate) fn resolve(
cfg: &Config,
db: &Db,
pb: &Pkgbase,