From 5c36c119f9448baf6bfe5245c6ebac1aa09d5b43 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 8 Apr 2021 16:14:06 +0200 Subject: 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 Tested-by: Matthias Beyer --- src/repository/repository.rs | 16 ++++++++++------ 1 file 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::>>()?; -- cgit v1.2.3