summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-02-16 07:58:13 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-02-16 08:02:21 +0100
commit04e7602e34987b832e1d2e95405f61443b30a641 (patch)
treeed79c8d93cf9e3e5cfbb765bbbf8df67539b0b3a /src/db
parent09f5560442b13f8bf58152b36d8819ec309363fc (diff)
Fix find_artifacts() to not fail if FS object moved
This patch fixes a bug in the crate::db::find_artifacts() implementation, which caused the function to fail if the filesystem object was removed. For example, if a package X was built and released, but then removed on the filesystem, this function would try to find that object but fail and cause butido to stop. Because that's not what we want, this function does not fail anymore but simply ignore the not-found object and return nothing for it. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net> Tested-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/db')
-rw-r--r--src/db/find_artifacts.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/db/find_artifacts.rs b/src/db/find_artifacts.rs
index 82a2798..613e63f 100644
--- a/src/db/find_artifacts.rs
+++ b/src/db/find_artifacts.rs
@@ -11,7 +11,6 @@
use std::path::PathBuf;
use std::sync::Arc;
-use anyhow::anyhow;
use anyhow::Error;
use anyhow::Result;
use chrono::NaiveDateTime;
@@ -23,6 +22,7 @@ use diesel::QueryDsl;
use diesel::RunQueryDsl;
use log::trace;
use resiter::AndThen;
+use resiter::FilterMap;
use resiter::Map;
use crate::config::Configuration;
@@ -213,16 +213,21 @@ pub fn find_artifacts<'a>(
);
if let Some(art) = staging.get(&artpath) {
trace!("Found in staging: {:?}", art);
- return staging.root_path().join(art).map(|p| (p, ndt));
+ return staging.root_path().join(art).map(|p| (p, ndt)).map(Some)
}
}
- let art = release_store
- .get(&artpath)
- .ok_or_else(|| anyhow!("Failed to find artifact for: {:?}", artpath))?;
- trace!("Found in release: {:?}", art);
- release_store.root_path().join(art).map(|p| (p, ndt))
+ // If we cannot find the artifact in the release store either, we return None.
+ // This is the case if there indeed was a release, but it was removed from the
+ // filesystem.
+ if let Some(art) = release_store.get(&artpath) {
+ trace!("Found in release: {:?}", art);
+ return release_store.root_path().join(art).map(|p| (p, ndt)).map(Some)
+ }
+
+ Ok(None)
})
+ .filter_map_ok(|opt| opt)
.collect::<Result<Vec<(FullArtifactPath<'a>, Option<NaiveDateTime>)>>>()
})
}