From 9f119061518ec64f6ae842b40581c93adb2496a1 Mon Sep 17 00:00:00 2001 From: phiresky Date: Wed, 8 Apr 2020 12:40:41 +0200 Subject: [PATCH] change binary search path, fix #32 --- src/bin/rga.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bin/rga.rs b/src/bin/rga.rs index f4056b2..a0cc599 100644 --- a/src/bin/rga.rs +++ b/src/bin/rga.rs @@ -116,9 +116,11 @@ fn add_exe_to_path() -> Fallible<()> { exe.pop(); // dirname let path = env::var_os("PATH").unwrap_or("".into()); - let mut paths = env::split_paths(&path).collect::>(); - paths.push(exe.to_owned()); // append: this way system PATH gets higher priority than bundled versions - paths.push(exe.join("lib")); + let paths = env::split_paths(&path).collect::>(); + // prepend: prefer bundled versions to system-installed versions of binaries + // solves https://github.com/phiresky/ripgrep-all/issues/32 + // may be somewhat of a security issue if rga binary is in installed in unprivileged locations + let paths = [&[exe.to_owned(), exe.join("lib")], &paths[..]].concat(); let new_path = env::join_paths(paths)?; env::set_var("PATH", &new_path); Ok(())