summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-02-22 14:18:23 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-02-22 14:18:23 +0100
commit010c61f6140513b0dc2582e6bb11cd5913bf4881 (patch)
treecdc28394910727d9e06e0c2bbf1598dadf2b1720 /src
parent3c7f31f0fa8350f65cf3e74955a22eef0674cd4d (diff)
parentfb8296ec16627f11b555bed1e2678437280302ab (diff)
Merge branch 'staging-reuse-is-submit-reuse'
Diffstat (limited to 'src')
-rw-r--r--src/commands/build.rs29
-rw-r--r--src/db/models/submit.rs3
2 files changed, 24 insertions, 8 deletions
diff --git a/src/commands/build.rs b/src/commands/build.rs
index 63651d4..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,8 +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();
- println!("Submit {}, started {}", submit_id, now);
let shebang = Shebang::from({
matches
@@ -167,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() {
@@ -194,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")?;