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 -- 2.7.4
Richard W.M. Jones
2016-Aug-23 14:09 UTC
Re: [Libguestfs] [PATCH] mllib: do not assume $PATH is set
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 inACK. 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
Seemingly Similar Threads
- [PATCH] mllib: move which and its exception from dib
- Re: [PATCH v4 4/6] mllib: modify nsplit to take optional noempty and count arguments
- [PATCH] mllib: check for executable existance in run_command (RHBZ#1362357)
- [PATCH 1/2] mllib: move remove_duplicates from v2v
- [PATCH] generator: Share Common_utils code.