~science-computing/butido

5c36c119f9448baf6bfe5245c6ebac1aa09d5b43 — Matthias Beyer 6 months ago a0bcd7e
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>
1 files changed, 10 insertions(+), 6 deletions(-)

M src/repository/repository.rs
M src/repository/repository.rs => src/repository/repository.rs +10 -6
@@ 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<_>>>()?;