|
|
e76f14 |
From f0891277008c6535aa12e2e9b1b52eb8da6bc678 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
e76f14 |
Date: Thu, 4 Feb 2016 10:45:20 +0100
|
|
|
e76f14 |
Subject: [PATCH] daemon: glob: add optarg to control trailing slash for dirs
|
|
|
e76f14 |
|
|
|
e76f14 |
Add a new optional bool "directoryslash" to indicate whether the caller
|
|
|
e76f14 |
wants trailing slashes in names of directories, defaulting to true (the
|
|
|
e76f14 |
current behaviour); this helps with interoperability with other tools
|
|
|
e76f14 |
(such as rm).
|
|
|
e76f14 |
|
|
|
e76f14 |
Related to RHBZ#1293271.
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit 01f46e4e3128b8d8ab009ca198de440e776c2cd6)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
daemon/glob.c | 11 +++++++++--
|
|
|
e76f14 |
generator/actions.ml | 21 ++++++++++++++++-----
|
|
|
e76f14 |
gobject/Makefile.inc | 2 ++
|
|
|
e76f14 |
po/POTFILES | 1 +
|
|
|
e76f14 |
4 files changed, 28 insertions(+), 7 deletions(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/daemon/glob.c b/daemon/glob.c
|
|
|
e76f14 |
index 45fb30f..a22fd33 100644
|
|
|
e76f14 |
--- a/daemon/glob.c
|
|
|
e76f14 |
+++ b/daemon/glob.c
|
|
|
e76f14 |
@@ -26,14 +26,21 @@
|
|
|
e76f14 |
#include "actions.h"
|
|
|
e76f14 |
|
|
|
e76f14 |
char **
|
|
|
e76f14 |
-do_glob_expand (const char *pattern)
|
|
|
e76f14 |
+do_glob_expand (const char *pattern, int directoryslash)
|
|
|
e76f14 |
{
|
|
|
e76f14 |
int r;
|
|
|
e76f14 |
glob_t buf = { .gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0 };
|
|
|
e76f14 |
+ int flags = GLOB_BRACE | GLOB_MARK;
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ /* GLOB_MARK is default, unless the user explicitly disabled it. */
|
|
|
e76f14 |
+ if ((optargs_bitmask & GUESTFS_GLOB_EXPAND_DIRECTORYSLASH_BITMASK)
|
|
|
e76f14 |
+ && !directoryslash) {
|
|
|
e76f14 |
+ flags &= ~GLOB_MARK;
|
|
|
e76f14 |
+ }
|
|
|
e76f14 |
|
|
|
e76f14 |
/* glob(3) in glibc never calls chdir, so this seems to be safe: */
|
|
|
e76f14 |
CHROOT_IN;
|
|
|
e76f14 |
- r = glob (pattern, GLOB_MARK|GLOB_BRACE, NULL, &buf;;
|
|
|
e76f14 |
+ r = glob (pattern, flags, NULL, &buf;;
|
|
|
e76f14 |
CHROOT_OUT;
|
|
|
e76f14 |
|
|
|
e76f14 |
if (r == GLOB_NOMATCH) { /* Return an empty list instead of an error. */
|
|
|
e76f14 |
diff --git a/generator/actions.ml b/generator/actions.ml
|
|
|
e76f14 |
index dfeb34c..998caa5 100644
|
|
|
e76f14 |
--- a/generator/actions.ml
|
|
|
e76f14 |
+++ b/generator/actions.ml
|
|
|
e76f14 |
@@ -5908,27 +5908,34 @@ See also: C<guestfs_command_lines>" };
|
|
|
e76f14 |
* start with "/". There is no concept of "cwd" in libguestfs,
|
|
|
e76f14 |
* hence no "."-relative names.
|
|
|
e76f14 |
*)
|
|
|
e76f14 |
- style = RStringList "paths", [Pathname "pattern"], [];
|
|
|
e76f14 |
+ style = RStringList "paths", [Pathname "pattern"], [OBool "directoryslash"];
|
|
|
e76f14 |
proc_nr = Some 113;
|
|
|
e76f14 |
+ once_had_no_optargs = true;
|
|
|
e76f14 |
tests = [
|
|
|
e76f14 |
InitScratchFS, Always, TestResult (
|
|
|
e76f14 |
[["mkdir_p"; "/glob_expand/b/c"];
|
|
|
e76f14 |
["touch"; "/glob_expand/b/c/d"];
|
|
|
e76f14 |
["touch"; "/glob_expand/b/c/e"];
|
|
|
e76f14 |
- ["glob_expand"; "/glob_expand/b/c/*"]],
|
|
|
e76f14 |
+ ["glob_expand"; "/glob_expand/b/c/*"; ""]],
|
|
|
e76f14 |
"is_string_list (ret, 2, \"/glob_expand/b/c/d\", \"/glob_expand/b/c/e\")"), [];
|
|
|
e76f14 |
InitScratchFS, Always, TestResult (
|
|
|
e76f14 |
[["mkdir_p"; "/glob_expand2/b/c"];
|
|
|
e76f14 |
["touch"; "/glob_expand2/b/c/d"];
|
|
|
e76f14 |
["touch"; "/glob_expand2/b/c/e"];
|
|
|
e76f14 |
- ["glob_expand"; "/glob_expand2/*/c/*"]],
|
|
|
e76f14 |
+ ["glob_expand"; "/glob_expand2/*/c/*"; ""]],
|
|
|
e76f14 |
"is_string_list (ret, 2, \"/glob_expand2/b/c/d\", \"/glob_expand2/b/c/e\")"), [];
|
|
|
e76f14 |
InitScratchFS, Always, TestResult (
|
|
|
e76f14 |
[["mkdir_p"; "/glob_expand3/b/c"];
|
|
|
e76f14 |
["touch"; "/glob_expand3/b/c/d"];
|
|
|
e76f14 |
["touch"; "/glob_expand3/b/c/e"];
|
|
|
e76f14 |
- ["glob_expand"; "/glob_expand3/*/x/*"]],
|
|
|
e76f14 |
- "is_string_list (ret, 0)"), []
|
|
|
e76f14 |
+ ["glob_expand"; "/glob_expand3/*/x/*"; ""]],
|
|
|
e76f14 |
+ "is_string_list (ret, 0)"), [];
|
|
|
e76f14 |
+ InitScratchFS, Always, TestResult (
|
|
|
e76f14 |
+ [["mkdir_p"; "/glob_expand4/b/c"];
|
|
|
e76f14 |
+ ["touch"; "/glob_expand4/b1"];
|
|
|
e76f14 |
+ ["touch"; "/glob_expand4/c1"];
|
|
|
e76f14 |
+ ["glob_expand"; "/glob_expand4/b*"; "false"]],
|
|
|
e76f14 |
+ "is_string_list (ret, 2, \"/glob_expand4/b\", \"/glob_expand4/b1\")"), [];
|
|
|
e76f14 |
];
|
|
|
e76f14 |
shortdesc = "expand a wildcard path";
|
|
|
e76f14 |
longdesc = "\
|
|
|
e76f14 |
@@ -5943,6 +5950,10 @@ It is just a wrapper around the C L<glob(3)> function
|
|
|
e76f14 |
with flags C<GLOB_MARK|GLOB_BRACE>.
|
|
|
e76f14 |
See that manual page for more details.
|
|
|
e76f14 |
|
|
|
e76f14 |
+C<directoryslash> controls whether use the C<GLOB_MARK> flag for
|
|
|
e76f14 |
+L<glob(3)>, and it defaults to true. It can be explicitly set as
|
|
|
e76f14 |
+off to return no trailing slashes in filenames of directories.
|
|
|
e76f14 |
+
|
|
|
e76f14 |
Notice that there is no equivalent command for expanding a device
|
|
|
e76f14 |
name (eg. F</dev/sd*>). Use C<guestfs_list_devices>,
|
|
|
e76f14 |
C<guestfs_list_partitions> etc functions instead." };
|
|
|
e76f14 |
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
|
|
|
e76f14 |
index 20c98ff..4b99a78 100644
|
|
|
e76f14 |
--- a/gobject/Makefile.inc
|
|
|
e76f14 |
+++ b/gobject/Makefile.inc
|
|
|
e76f14 |
@@ -69,6 +69,7 @@ guestfs_gobject_headers= \
|
|
|
e76f14 |
include/guestfs-gobject/optargs-disk_create.h \
|
|
|
e76f14 |
include/guestfs-gobject/optargs-e2fsck.h \
|
|
|
e76f14 |
include/guestfs-gobject/optargs-fstrim.h \
|
|
|
e76f14 |
+ include/guestfs-gobject/optargs-glob_expand.h \
|
|
|
e76f14 |
include/guestfs-gobject/optargs-grep.h \
|
|
|
e76f14 |
include/guestfs-gobject/optargs-hivex_open.h \
|
|
|
e76f14 |
include/guestfs-gobject/optargs-inspect_get_icon.h \
|
|
|
e76f14 |
@@ -154,6 +155,7 @@ guestfs_gobject_sources= \
|
|
|
e76f14 |
src/optargs-disk_create.c \
|
|
|
e76f14 |
src/optargs-e2fsck.c \
|
|
|
e76f14 |
src/optargs-fstrim.c \
|
|
|
e76f14 |
+ src/optargs-glob_expand.c \
|
|
|
e76f14 |
src/optargs-grep.c \
|
|
|
e76f14 |
src/optargs-hivex_open.c \
|
|
|
e76f14 |
src/optargs-inspect_get_icon.c \
|
|
|
e76f14 |
diff --git a/po/POTFILES b/po/POTFILES
|
|
|
e76f14 |
index d4058ac..a5f3f9e 100644
|
|
|
e76f14 |
--- a/po/POTFILES
|
|
|
e76f14 |
+++ b/po/POTFILES
|
|
|
e76f14 |
@@ -194,6 +194,7 @@ gobject/src/optargs-cpio_out.c
|
|
|
e76f14 |
gobject/src/optargs-disk_create.c
|
|
|
e76f14 |
gobject/src/optargs-e2fsck.c
|
|
|
e76f14 |
gobject/src/optargs-fstrim.c
|
|
|
e76f14 |
+gobject/src/optargs-glob_expand.c
|
|
|
e76f14 |
gobject/src/optargs-grep.c
|
|
|
e76f14 |
gobject/src/optargs-hivex_open.c
|
|
|
e76f14 |
gobject/src/optargs-inspect_get_icon.c
|
|
|
e76f14 |
--
|
|
|
aa0300 |
2.7.4
|
|
|
e76f14 |
|