On 11/17/14 at 11:33pm, Allan McRae wrote: > When the system root is passed to fnmatch_patterns, it is stripped from > the start of the string before comparisions are made. > > Signed-off-by: Allan McRae <al...@archlinux.org> > --- > lib/libalpm/add.c | 4 ++-- > src/common/util-common.c | 9 ++++++++- > src/common/util-common.h | 2 +- > 3 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c > index 9f7c9fa..604e0c7 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(fnmatch_patterns(handle->noextract, entryname) == 0) { > + if(fnmatch_patterns(handle->noextract, entryname, NULL) == 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(fnmatch_patterns(handle->noupgrade, entryname) == 0) > { > + if(fnmatch_patterns(handle->noupgrade, entryname, NULL) > == 0) { > notouch = 1; > } else { > alpm_backup_t *backup; > diff --git a/src/common/util-common.c b/src/common/util-common.c > index 1930d64..63355a4 100644 > --- a/src/common/util-common.c > +++ b/src/common/util-common.c > @@ -110,14 +110,21 @@ int llstat(char *path, struct stat *buf) > * escaped. Subsequent matches override previous ones. > * @param patterns patterns to match against > * @param string string to check against pattern > + * @param root prefix to be stripped from string before comparison > * @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) > +int fnmatch_patterns(alpm_list_t *patterns, const char *string, const char > *root) > { > alpm_list_t *i; > char *pattern; > short inverted; > + size_t len = 0; > + > + if(root) { > + len = strlen(root); > + } > + string = string + len;
Why do this here? The caller can just as easily achieve this by calling fnmatch_patterns(patterns, string + strlen(root)) and may even be able to avoid duplicate strlen calls by caching the root length. > for(i = alpm_list_last(patterns); i; i = alpm_list_previous(i)) { > pattern = i->data; > diff --git a/src/common/util-common.h b/src/common/util-common.h > index 17f8d87..e731e52 100644 > --- a/src/common/util-common.h > +++ b/src/common/util-common.h > @@ -30,7 +30,7 @@ char *mdirname(const char *path); > > int llstat(char *path, struct stat *buf); > > -int fnmatch_patterns(alpm_list_t *patterns, const char *string); > +int fnmatch_patterns(alpm_list_t *patterns, const char *string, const char > *root); > > char *safe_fgets(char *s, int size, FILE *stream); > > -- > 2.1.3