[Libguestfs] [PATCH 2/3] daemon: glob: add option for not returning dirs with trailing slash

Richard W.M. Jones rjones at redhat.com
Wed Feb 3 18:38:52 UTC 2016


On Wed, Feb 03, 2016 at 07:28:17PM +0100, Pino Toscano wrote:
> Add a new optional bool "nodirectoryslash", to indicate that the caller
> does not want trailing slashes in names of directories; this helps with
> interoperability with other tools (such as rm).

Hmm, double negative :-/

Can it be "directoryslash" (defaulting to true of course)?

>  char **
> -do_glob_expand (const char *pattern)
> +do_glob_expand (const char *pattern, int nodirectoryslash)

Since this function is using an optarg, it must consult optargs_bitmask
below, ie.

>  {
>    int r;
>    glob_t buf = { .gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0 };
> +  int flags = GLOB_BRACE;
> +
> +  if (!nodirectoryslash)
> +    flags |= GLOB_MARK;

(with the sense reversed as I mentioned above) it would be:

  if (optargs_bitmask & GUESTFS_GLOB_EXPAND_DIRECTORYSLASH_BITMASK) {
    if (directoryslash)
      flags |= GLOB_MARK;
  } else {
    flags |= GLOB_MARK; /* defaults to true for backwards compatibility */
  }

You could simplify that a bit, but that's the general idea.

Rest of the change is fine.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/




More information about the Libguestfs mailing list