summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-08 16:14:06 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-09 12:59:20 +0200
commitb2a68f896b444df551549caead9ab44bd76fdf22 (patch)
tree2a5080d1eb628ce43a873dec77c40683a4d2f41f
parent02c3414bbb0402611aea6e5f982c70ea8b513e5c (diff)
Fix: Error out if a patch file is missing
This patch fixes a bug where a patch file is not there. Before this patch, we were simply ignoring non-existing files in the iterator, because during development of this algorithm, it seemed to be the right idea because of the recursion that is happending. The patch-branch-patching that is happening in the recursion, that rewrites the pathes to the patches during the recursive loading of the packages, used to yield invalid pathes at some point, which simply could be ignored. That happened before that patch. But because during the development of the recursive loading, the scheme how this all works was changed, it does not yield invalid pathes anymore. Hence, we can be sure that either the file is here or it is not - which is an error then. I have to say that I'm not particularly good with recursion, but as far as my tests go, this seems to work as intended now. Signed-off-by: Matthias Beyer <matthias.beyer@atos.net> Tested-by: Matthias Beyer <matthias.beyer@atos.net> (cherry picked from commit 5c36c119f9448baf6bfe5245c6ebac1aa09d5b43)
-rw-r--r--src/repository/repository.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/repository/repository.rs b/src/repository/repository.rs
index 1681660..e01c28f 100644
--- a/src/repository/repository.rs
+++ b/src/repository/repository.rs
@@ -17,8 +17,8 @@ use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use log::trace;
+use resiter::AndThen;
use resiter::Map;
-use resiter::FilterMap;
use crate::package::Package;
use crate::package::PackageName;
@@ -138,13 +138,17 @@ impl Repository {
// the root directory of the repository.
.map(|patch| patch.into_str().map_err(Error::from))
.map_ok(|patch| path_relative_to_root.join(patch))
+ .inspect(|patch| trace!("Patch relative to root: {:?}", patch.as_ref().map(|p| p.display())))
- // if the patch file exists, use it (as config::Value), otherwise ignore the
- // element in the iterator
- .filter_map_ok(|patch| if patch.exists() {
- Some(config::Value::from(patch.display().to_string()))
+ // if the patch file exists, use it (as config::Value).
+ //
+ // Otherwise we have an error here, because we're refering to a non-existing file.
+ .and_then_ok(|patch| if patch.exists() {
+ trace!("Path to patch exists: {}", patch.display());
+ Ok(config::Value::from(patch.display().to_string()))
} else {
- None
+ trace!("Path to patch does not exist: {}", patch.display());
+ Err(anyhow!("Patch does not exist: {}", patch.display()))
})
.collect::<Result<Vec<_>>>()?;