diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-02-22 08:32:51 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-02-22 08:52:15 +0100 |
commit | fb8296ec16627f11b555bed1e2678437280302ab (patch) | |
tree | d7eb0eceefe88c14b6bbe03fdf145fcfbf452d7d /src/commands/build.rs | |
parent | 41a98f8d81f0f14ff05f4924ba708bb7cf1818cb (diff) |
Fix: Re-use submit UUID if staging directory is overwritten
This patch changes the behaviour if the staging directory is re-used.
If the staging directory is re-used, we take the submit UUID from there instead
of generating a new one.
This way, database entries are added to the already existing submit instead of
added to a new one, but the artifacts are put into the staging store of the
reused one.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Tested-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/commands/build.rs')
-rw-r--r-- | src/commands/build.rs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/commands/build.rs b/src/commands/build.rs index e639d29..05fb0d6 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -27,6 +27,7 @@ use itertools::Itertools; use log::{debug, info, trace, warn}; use tokio::sync::RwLock; use tokio_stream::StreamExt; +use uuid::Uuid; use crate::config::*; use crate::filestore::path::StoreRoot; @@ -62,7 +63,6 @@ pub async fn build( let _ = crate::ui::package_repo_cleanness_check(&repo_root)?; let now = chrono::offset::Local::now().naive_local(); - let submit_id = uuid::Uuid::new_v4(); let shebang = Shebang::from({ matches @@ -166,20 +166,34 @@ pub async fn build( r.map(RwLock::new).map(Arc::new)? }; - let (staging_store, staging_dir) = { + let (staging_store, staging_dir, submit_id) = { let bar_staging_loading = progressbars.bar(); bar_staging_loading.set_length(max_packages); - let p = if let Some(staging_dir) = matches.value_of("staging_dir").map(PathBuf::from) { + let (submit_id, p) = if let Some(staging_dir) = matches.value_of("staging_dir").map(PathBuf::from) { info!( "Setting staging dir to {} for this run", staging_dir.display() ); - staging_dir + + let uuid = staging_dir.file_name() + .ok_or_else(|| anyhow!("Seems not to be a directory: {}", staging_dir.display()))? + .to_owned() + .into_string() + .map_err(|_| anyhow!("Type conversion of staging dir name to UTF8 String")) + .context("Parsing staging dir name to UUID")?; + let uuid = Uuid::parse_str(&uuid) + .context("Parsing directory name as UUID") + .with_context(|| anyhow!("Seems not to be a submit UUID: {}", uuid))?; + + (uuid, staging_dir) } else { - config + let submit_id = uuid::Uuid::new_v4(); + let staging_dir = config .staging_directory() - .join(submit_id.hyphenated().to_string()) + .join(submit_id.hyphenated().to_string()); + + (submit_id, staging_dir) }; if !p.is_dir() { @@ -193,7 +207,7 @@ pub async fn build( } else { bar_staging_loading.finish_with_message("Failed to load staging"); } - r.map(RwLock::new).map(Arc::new).map(|store| (store, p))? + r.map(RwLock::new).map(Arc::new).map(|store| (store, p, submit_id))? }; let dag = { |