On Tue, Aug 23, 2016 at 04:00:18PM +0200, Pino Toscano wrote:
Make 'which' gracefully handle the case where $PATH is not
set
(it will raise Executable_not_found, but that is the expected thing to
do).
Related to RHBZ#1367839.
---
mllib/common_utils.ml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index fdca713..9210cf8 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -319,7 +319,9 @@ let protect ~f ~finally =
match r with Either ret -> ret | Or exn -> raise exn
let which executable =
- let paths = String.nsplit ":" (Sys.getenv "PATH") in
+ let paths =
+ try String.nsplit ":" (Sys.getenv "PATH")
+ with Not_found -> [] in
let paths = filter_map (
fun p ->
let path = p // executable in
ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages.
http://libguestfs.org