diff options
Diffstat (limited to 'src/pipeline/publish.rs')
| -rw-r--r-- | src/pipeline/publish.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs index 5d03a06..d54314e 100644 --- a/src/pipeline/publish.rs +++ b/src/pipeline/publish.rs @@ -58,7 +58,20 @@ fn index_artifacts(db: &Db, extra: &[PathBuf]) -> Result<Vec<PathBuf>> { } /// Publish the collected artifacts of a build. Returns the new release id. +/// One publish at a time per repo (§8.2, §9). With `max_concurrent_builds > 1` +/// two workers could otherwise interleave the index rewrite; the critical +/// section is the db file rewrite only, never a build. +static PUBLISH_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + pub fn publish(ctx: &Ctx) -> Result<i64> { + let _guard = match PUBLISH_LOCK.lock() { + Ok(g) => g, + // A previous publish panicked while holding it. The index on disk is + // still whatever was last renamed into place — atomic publish means a + // poisoned lock cannot have left a half-written db — so we clear the + // poison and continue rather than wedge the queue forever. + Err(p) => p.into_inner(), + }; let collect = Collect::load(&ctx.collect_path)?; if collect.packages.is_empty() { return Err(Error::invalid("nothing to publish")); |
