[pacman-dev] [PATCH 1/3] Make (_alpm_)fnmatch_patterns available to front-end
Allan McRae
allan at archlinux.org
Mon Nov 17 13:33:12 UTC 2014
This function will be useful in determining if any files are in the NoExtract
array when checking for missing files.
Signed-off-by: Allan McRae <allan at archlinux.org>
---
lib/libalpm/add.c | 4 ++--
lib/libalpm/util.c | 31 -------------------------------
lib/libalpm/util.h | 1 -
src/common/util-common.c | 32 ++++++++++++++++++++++++++++++++
src/common/util-common.h | 4 ++++
5 files changed, 38 insertions(+), 34 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index bbf2a51..9f7c9fa 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -190,7 +190,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
}
/* if a file is in NoExtract then we never extract it */
- if(_alpm_fnmatch_patterns(handle->noextract, entryname) == 0) {
+ if(fnmatch_patterns(handle->noextract, entryname) == 0) {
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoExtract,"
" skipping extraction of %s\n",
entryname, filename);
@@ -266,7 +266,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
} else {
/* case 3: */
/* if file is in NoUpgrade, don't touch it */
- if(_alpm_fnmatch_patterns(handle->noupgrade, entryname) == 0) {
+ if(fnmatch_patterns(handle->noupgrade, entryname) == 0) {
notouch = 1;
} else {
alpm_backup_t *backup;
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 43d0d7b..39ac890 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -1224,37 +1224,6 @@ int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int a
return ret;
}
-/** Checks whether a string matches at least one shell wildcard pattern.
- * Checks for matches with fnmatch. Matches are inverted by prepending
- * patterns with an exclamation mark. Preceding exclamation marks may be
- * escaped. Subsequent matches override previous ones.
- * @param patterns patterns to match against
- * @param string string to check against pattern
- * @return 0 if string matches pattern, negative if they don't match and
- * positive if the last match was inverted
- */
-int _alpm_fnmatch_patterns(alpm_list_t *patterns, const char *string)
-{
- alpm_list_t *i;
- char *pattern;
- short inverted;
-
- for(i = alpm_list_last(patterns); i; i = alpm_list_previous(i)) {
- pattern = i->data;
-
- inverted = pattern[0] == '!';
- if(inverted || pattern[0] == '\\') {
- pattern++;
- }
-
- if(_alpm_fnmatch(pattern, string) == 0) {
- return inverted;
- }
- }
-
- return -1;
-}
-
/** Checks whether a string matches a shell wildcard pattern.
* Wrapper around fnmatch.
* @param pattern pattern to match against
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 6f47073..9422646 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -137,7 +137,6 @@ alpm_time_t _alpm_parsedate(const char *line);
int _alpm_raw_cmp(const char *first, const char *second);
int _alpm_raw_ncmp(const char *first, const char *second, size_t max);
int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode);
-int _alpm_fnmatch_patterns(alpm_list_t *patterns, const char *string);
int _alpm_fnmatch(const void *pattern, const void *string);
void *_alpm_realloc(void **data, size_t *current, const size_t required);
void *_alpm_greedy_grow(void **data, size_t *current, const size_t required);
diff --git a/src/common/util-common.c b/src/common/util-common.c
index ab74e7c..1930d64 100644
--- a/src/common/util-common.c
+++ b/src/common/util-common.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <fnmatch.h>
#include "util-common.h"
@@ -103,6 +104,37 @@ int llstat(char *path, struct stat *buf)
return ret;
}
+/** Checks whether a string matches at least one shell wildcard pattern.
+ * Checks for matches with fnmatch. Matches are inverted by prepending
+ * patterns with an exclamation mark. Preceding exclamation marks may be
+ * escaped. Subsequent matches override previous ones.
+ * @param patterns patterns to match against
+ * @param string string to check against pattern
+ * @return 0 if string matches pattern, negative if they don't match and
+ * positive if the last match was inverted
+ */
+int fnmatch_patterns(alpm_list_t *patterns, const char *string)
+{
+ alpm_list_t *i;
+ char *pattern;
+ short inverted;
+
+ for(i = alpm_list_last(patterns); i; i = alpm_list_previous(i)) {
+ pattern = i->data;
+
+ inverted = pattern[0] == '!';
+ if(inverted || pattern[0] == '\\') {
+ pattern++;
+ }
+
+ if(fnmatch(pattern, string, 0) == 0) {
+ return inverted;
+ }
+ }
+
+ return -1;
+}
+
/** Wrapper around fgets() which properly handles EINTR
* @param s string to read into
* @param size maximum length to read
diff --git a/src/common/util-common.h b/src/common/util-common.h
index ca8db5a..17f8d87 100644
--- a/src/common/util-common.h
+++ b/src/common/util-common.h
@@ -20,6 +20,8 @@
#ifndef _PM_UTIL_COMMON_H
#define _PM_UTIL_COMMON_H
+#include <alpm_list.h>
+
#include <stdio.h>
#include <sys/stat.h> /* struct stat */
@@ -28,6 +30,8 @@ char *mdirname(const char *path);
int llstat(char *path, struct stat *buf);
+int fnmatch_patterns(alpm_list_t *patterns, const char *string);
+
char *safe_fgets(char *s, int size, FILE *stream);
#ifndef HAVE_STRNDUP
--
2.1.3
More information about the pacman-dev
mailing list