From 52f58e09a69617393895164f0731f173fe3dd618 Mon Sep 17 00:00:00 2001 From: Frederik Delaere Date: Fri, 14 Sep 2018 08:31:37 +0200 Subject: [PATCH] test if the path exists before telling the script that this file needs to be loaded. This fixes the bug where software with the same name exists in two different modulepaths --- src/rsmodules.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rsmodules.rs b/src/rsmodules.rs index e4c20cc..40fe295 100644 --- a/src/rsmodules.rs +++ b/src/rsmodules.rs @@ -447,7 +447,11 @@ fn module_action(rsmod: &mut Rsmodule, action: &str) { if found && module.0.starts_with(mdl) && module.1 == 1 { selected_module = module.0.as_ref(); let testpath = format!("{}/{}", modulepath, module.0); - modulefile = PathBuf::from(&testpath); + // if a modulefile is already found, don't overwrite it with a + // possible non existing file + if Path::new(&testpath).exists() && Path::new(&testpath).is_file() { + modulefile = PathBuf::from(&testpath); + } break 'outer; } @@ -460,8 +464,11 @@ fn module_action(rsmod: &mut Rsmodule, action: &str) { selected_module = module.0.as_ref(); found = true; let testpath = format!("{}/{}", modulepath, module.0); - modulefile = PathBuf::from(&testpath); - + // if a modulefile is already found, don't overwrite it with a + // possible non existing file + if Path::new(&testpath).exists() && Path::new(&testpath).is_file() { + modulefile = PathBuf::from(&testpath); + } // don't break out of the outer loop, their might be a module // file marked as D //break 'outer; @@ -515,7 +522,6 @@ fn module_action(rsmod: &mut Rsmodule, action: &str) { } // finaly load|unload|info the module - output(format!("# {} {}\n", action, selected_module)); run_modulefile(&modulefile, rsmod, selected_module, action);