ee316a0bf8
- Resolves: 1246743
124 lines
3.3 KiB
Diff
124 lines
3.3 KiB
Diff
From d14ecfe587efbe80e5534161dbd3a4f7158b4e2b Mon Sep 17 00:00:00 2001
|
|
From: Lubos Kardos <lkardos@redhat.com>
|
|
Date: Mon, 27 Jul 2015 11:22:19 +0200
|
|
Subject: [PATCH] Enable {} expansion in rpmGlob() (rhbz:1246743)
|
|
|
|
---
|
|
rpmio/rpmglob.c | 42 ++++++++++++++++++++++++++++++++----------
|
|
1 file changed, 32 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/rpmio/rpmglob.c b/rpmio/rpmglob.c
|
|
index 4fc106d..597ac5c 100644
|
|
--- a/rpmio/rpmglob.c
|
|
+++ b/rpmio/rpmglob.c
|
|
@@ -150,7 +150,7 @@ static inline const char *next_brace_sub(const char *begin)
|
|
return cp;
|
|
}
|
|
|
|
-static int __glob_pattern_p(const char *pattern, int quote);
|
|
+static int __glob_pattern_p(const char *pattern, int flags);
|
|
|
|
/* Do glob searching for PATTERN, placing results in PGLOB.
|
|
The bits defined above may be set in FLAGS.
|
|
@@ -419,7 +419,7 @@ glob(const char *pattern, int flags,
|
|
return GLOB_NOMATCH;
|
|
}
|
|
|
|
- if (__glob_pattern_p(dirname, !(flags & GLOB_NOESCAPE))) {
|
|
+ if (__glob_pattern_p(dirname, flags)) {
|
|
/* The directory name contains metacharacters, so we
|
|
have to glob for the directory, and then glob for
|
|
the pattern in each directory found. */
|
|
@@ -646,10 +646,11 @@ static int prefix_array(const char *dirname, char **array, size_t n)
|
|
|
|
/* Return nonzero if PATTERN contains any metacharacters.
|
|
Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
|
|
-static int __glob_pattern_p(const char *pattern, int quote)
|
|
+static int __glob_pattern_p(const char *pattern, int flags)
|
|
{
|
|
register const char *p;
|
|
- int open = 0;
|
|
+ int openBrackets = 0;
|
|
+ int openBraces = 0;
|
|
|
|
for (p = pattern; *p != '\0'; ++p)
|
|
switch (*p) {
|
|
@@ -658,18 +659,29 @@ static int __glob_pattern_p(const char *pattern, int quote)
|
|
return 1;
|
|
|
|
case '\\':
|
|
- if (quote && p[1] != '\0')
|
|
+ if (!(flags & GLOB_NOESCAPE) && p[1] != '\0')
|
|
++p;
|
|
break;
|
|
|
|
case '[':
|
|
- open = 1;
|
|
+ openBrackets = 1;
|
|
break;
|
|
|
|
case ']':
|
|
- if (open)
|
|
+ if (openBrackets)
|
|
return 1;
|
|
break;
|
|
+
|
|
+ case '{':
|
|
+ if (flags & GLOB_BRACE)
|
|
+ openBraces = 1;
|
|
+ break;
|
|
+
|
|
+ case '}':
|
|
+ if (openBraces)
|
|
+ return 1;
|
|
+ break;
|
|
+
|
|
}
|
|
|
|
return 0;
|
|
@@ -694,7 +706,7 @@ glob_in_dir(const char *pattern, const char *directory, int flags,
|
|
int meta;
|
|
int save;
|
|
|
|
- meta = __glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE));
|
|
+ meta = __glob_pattern_p(pattern, flags);
|
|
if (meta == 0) {
|
|
if (flags & (GLOB_NOCHECK | GLOB_NOMAGIC))
|
|
/* We need not do any tests. The PATTERN contains no meta
|
|
@@ -844,6 +856,8 @@ int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr)
|
|
int i, j;
|
|
int rc;
|
|
|
|
+ gflags |= GLOB_BRACE;
|
|
+
|
|
if (home != NULL && strlen(home) > 0)
|
|
gflags |= GLOB_TILDE;
|
|
|
|
@@ -874,7 +888,9 @@ int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr)
|
|
int dir_only = (plen > 0 && path[plen-1] == '/');
|
|
glob_t gl;
|
|
|
|
- if (!local || (!rpmIsGlob(av[j], 0) && strchr(path, '~') == NULL)) {
|
|
+ if (!local || (!rpmIsGlob(av[j], GLOB_NOESCAPE | flags) &&
|
|
+ strchr(path, '~') == NULL)) {
|
|
+
|
|
argvAdd(&argv, av[j]);
|
|
continue;
|
|
}
|
|
@@ -966,5 +982,11 @@ exit:
|
|
|
|
int rpmIsGlob(const char * pattern, int quote)
|
|
{
|
|
- return __glob_pattern_p(pattern, quote);
|
|
+ int flags = 0;
|
|
+ if (!quote) {
|
|
+ flags |= GLOB_NOESCAPE;
|
|
+ }
|
|
+ flags |= GLOB_BRACE;
|
|
+
|
|
+ return __glob_pattern_p(pattern, flags);
|
|
}
|
|
--
|
|
1.9.3
|
|
|