diff options
-rw-r--r-- | src/commands/build.rs | 28 | ||||
-rw-r--r-- | src/db/models/submit.rs | 3 |
2 files changed, 24 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 = { diff --git a/src/db/models/submit.rs b/src/db/models/submit.rs index 7792adf..154ed1b 100644 --- a/src/db/models/submit.rs +++ b/src/db/models/submit.rs @@ -63,7 +63,10 @@ impl Submit { diesel::insert_into(submits::table) .values(&new_submit) + + // required because if we re-use the staging store, we do not create a new UUID but re-use the old one .on_conflict_do_nothing() + .execute(database_connection) .context("Inserting new submit into submits table")?; |