diff options
Diffstat (limited to 'src/watch/upstream.rs')
| -rw-r--r-- | src/watch/upstream.rs | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index 7987178..523574a 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -5,7 +5,11 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Condvar, Mutex}; use crate::config::Config; -use crate::db::{self, model::*, Db, Pkgbase}; +use crate::db::{ + self, + model::{Recipe, StageBCacheRow, UpstreamPin}, + Db, Pkgbase, +}; use crate::error::{Error, Result, TransientCause}; use crate::git; @@ -116,12 +120,7 @@ pub(crate) struct StageB { impl StageB { fn from_cache(row: StageBCacheRow) -> Self { - StageB { - epoch: row.epoch, - pkgver: row.pkgver, - pkgrel: row.pkgrel, - pins: row.pins, - } + StageB { epoch: row.epoch, pkgver: row.pkgver, pkgrel: row.pkgrel, pins: row.pins } } fn as_row(&self) -> StageBCacheRow { @@ -143,14 +142,14 @@ static SLOT_LOCK: Mutex<()> = Mutex::new(()); /// only way to reach it, and the alias is what carries the /// feature-conditional visibility. mod stage_b_slot { - use super::*; + use super::{Ordering, RUNNING, SLOT_FREE, SLOT_LOCK}; pub struct StageBSlot(()); impl StageBSlot { pub fn acquire(cap: usize) -> Self { let cap = cap.max(1); - let guard = SLOT_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let guard = SLOT_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner); let mut guard = guard; loop { let n = RUNNING.load(Ordering::SeqCst); @@ -159,7 +158,7 @@ mod stage_b_slot { drop(guard); return StageBSlot(()); } - guard = SLOT_FREE.wait(guard).unwrap_or_else(|e| e.into_inner()); + guard = SLOT_FREE.wait(guard).unwrap_or_else(std::sync::PoisonError::into_inner); } } } @@ -191,7 +190,7 @@ pub(crate) fn resolve( recipe_hash: &str, stage_a: &StageA, ) -> Result<Option<StageB>> { - if !recipe.source_entries.iter().any(|e| e.is_vcs()) { + if !recipe.source_entries.iter().any(super::super::db::model::SourceEntry::is_vcs) { return Ok(None); } let tip_hash = tip_hash(&stage_a.pins); @@ -225,11 +224,11 @@ fn run( continue; } let cache = cfg.vcs_cache_path(&pin.url); - if !cache.exists() { + if cache.exists() { + let _ = git::fetch_and_head(&cache); + } else { git::clone_bare(&pin.url, &cache) .map_err(|e| Error::transient(TransientCause::Upstream(format!("vcs_cache clone {}: {e}", pin.url))))?; - } else { - let _ = git::fetch_and_head(&cache); } if let Ok(local) = git::head(&cache) { if !local.is_empty() && git::has_commit(&cache, &pin.commit) { @@ -251,10 +250,7 @@ fn run( let out = cmd.output()?; let _ = std::fs::remove_dir_all(&scratch); if !out.status.success() { - return Err(Error::transient(format!( - "makepkg --vercheck: {}", - String::from_utf8_lossy(&out.stderr).trim() - ))); + return Err(Error::transient(format!("makepkg --vercheck: {}", String::from_utf8_lossy(&out.stderr).trim()))); } let text = String::from_utf8_lossy(&out.stdout).trim().to_string(); let (pkgver, pkgrel) = match text.rsplit_once('-') { @@ -264,12 +260,7 @@ fn run( if pkgver.is_empty() { return Err(Error::other(format!("makepkg --vercheck produced {text:?}"))); } - Ok(StageB { - epoch: recipe.epoch.clone(), - pkgver, - pkgrel, - pins, - }) + Ok(StageB { epoch: recipe.epoch.clone(), pkgver, pkgrel, pins }) } fn default_branch(cache: &std::path::Path) -> Option<String> { @@ -280,16 +271,15 @@ fn default_branch(cache: &std::path::Path) -> Option<String> { } pub fn tip_hash(pins: &[UpstreamPin]) -> String { - let mut v: Vec<String> = pins - .iter() - .map(|p| format!("{}:{}:{}", p.index, p.url, p.commit)) - .collect(); + let mut v: Vec<String> = pins.iter().map(|p| format!("{}:{}:{}", p.index, p.url, p.commit)).collect(); v.sort(); crate::hash::hex_str(&v.join("\n")) } fn scratch_dir(cfg: &Config, pkgbase: &str, recipe_hash: &str, tip_hash: &str) -> PathBuf { - cfg.staging_dir() - .join("vercheck") - .join(format!("{pkgbase}-{}-{}", &recipe_hash[..8.min(recipe_hash.len())], &tip_hash[..8.min(tip_hash.len())])) + cfg.staging_dir().join("vercheck").join(format!( + "{pkgbase}-{}-{}", + &recipe_hash[..8.min(recipe_hash.len())], + &tip_hash[..8.min(tip_hash.len())] + )) } |
