[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH 1/2] mllib: allow external_command to return [] on nonzero return value

On Wed, Mar 18, 2015 at 05:20:06PM +0100, Maros Zatko wrote:
> This is useful for probing probing for cache files such as:
> external_command ?ignore_error:(Some true) ~prog "ls .cache/something.*"
> will return command output (matched files) on its success or empty list
> whenits exit code is other than 0 (there are no such files).

I would write this as:

  let files = Sys.readdir ".cache" inm
  let files = Array.to_list files in
  let files = List.filter (fun s -> string_prefix s "something.") in

  or if you just want to check existence of any something.* file:

  let file_exists = List.exists (fun s -> string_prefix s "something.") in


Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]