* findmatchingname():
When the bzip-pkg handling was introduced, a dewey pattern (foo>1) may get a character-class-pattern attached (.t[bg]z), and the code was not prepared to match that. I've special-cased handling of character-class pkg suffixes for ".t[bg]z", and when scanning a dir in findmatchingname() now both the 'first' part of the pattern (e.g. "foo>1") and the suffix (e.g. ".t[bg]z") must match the file, hence the two pmatch() calls. * findbestmatchingname_fn(): Caught a case where ".t[bg]z" was not properly handled. Must do the same suffix-processing again here! Fixes PR 11856 by Dan McMahill <mcmahill@mit.edu>
This commit is contained in:
parent
e6d2cd0771
commit
6e6337b43d
@ -1,11 +1,11 @@
|
||||
/* $NetBSD: str.c,v 1.24 2000/12/13 03:17:55 hubertf Exp $ */
|
||||
/* $NetBSD: str.c,v 1.25 2001/01/01 22:07:35 hubertf Exp $ */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp";
|
||||
#else
|
||||
__RCSID("$NetBSD: str.c,v 1.24 2000/12/13 03:17:55 hubertf Exp $");
|
||||
__RCSID("$NetBSD: str.c,v 1.25 2001/01/01 22:07:35 hubertf Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -287,23 +287,81 @@ int
|
||||
findmatchingname(const char *dir, const char *pattern, matchfn match, char *data)
|
||||
{
|
||||
struct dirent *dp;
|
||||
char tmp_pattern[256];
|
||||
DIR *dirp;
|
||||
int found;
|
||||
char *pat_tgz, *file_tgz; /* ptr to .tgz */
|
||||
char *pat_tbz, *file_tbz; /* ptr to .tbz */
|
||||
char *pat_tbgz, *file_tbgz; /* ptr to .t[bg]z */
|
||||
char pat_sfx[256], file_sfx[256]; /* suffixes */
|
||||
|
||||
found = 0;
|
||||
if ((dirp = opendir(dir)) == (DIR *) NULL) {
|
||||
/* warnx("can't opendir dir '%s'", dir); */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* chop off any possible suffix off 'pattern' and
|
||||
* store it in pat_sfx
|
||||
*/
|
||||
strcpy(tmp_pattern, pattern);
|
||||
pat_sfx[0] = '\0';
|
||||
pat_tgz = strstr(tmp_pattern, ".tgz");
|
||||
if (pat_tgz) {
|
||||
/* strip off any ".tgz" */
|
||||
strcpy(pat_sfx, pat_tgz);
|
||||
*pat_tgz = '\0';
|
||||
}
|
||||
pat_tbz = strstr(tmp_pattern, ".tbz");
|
||||
if (pat_tbz) {
|
||||
/* strip off any ".tbz" */
|
||||
strcpy(pat_sfx, pat_tbz);
|
||||
*pat_tbz = '\0';
|
||||
}
|
||||
pat_tbgz = strstr(tmp_pattern, ".t[bg]z");
|
||||
if (pat_tbgz) {
|
||||
/* strip off any ".t[bg]z" */
|
||||
strcpy(pat_sfx, pat_tbgz);
|
||||
*pat_tbgz = '\0';
|
||||
}
|
||||
|
||||
|
||||
while ((dp = readdir(dirp)) != (struct dirent *) NULL) {
|
||||
char tmp[FILENAME_MAX];
|
||||
char tmp_file[FILENAME_MAX];
|
||||
|
||||
if (strcmp(dp->d_name, ".") == 0 ||
|
||||
strcmp(dp->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
(void) snprintf(tmp, sizeof(tmp), "%s/%s", dir, dp->d_name);
|
||||
|
||||
if (pmatch(pattern, dp->d_name)) {
|
||||
/* chop off any possible suffix off 'tmp_file' and
|
||||
* store it in file_sfx
|
||||
*/
|
||||
strcpy(tmp_file, dp->d_name);
|
||||
file_sfx[0] = '\0';
|
||||
file_tgz = strstr(tmp_file, ".tgz");
|
||||
if (file_tgz) {
|
||||
/* strip off any ".tgz" */
|
||||
strcpy(file_sfx, file_tgz);
|
||||
*file_tgz = '\0';
|
||||
}
|
||||
file_tbz = strstr(tmp_file, ".tbz");
|
||||
if (file_tbz) {
|
||||
/* strip off any ".tbz" */
|
||||
strcpy(file_sfx, file_tbz);
|
||||
*file_tbz = '\0';
|
||||
}
|
||||
file_tbgz = strstr(tmp_file, ".t[bg]z");
|
||||
if (file_tbgz) {
|
||||
/* strip off any ".t[bg]z" */
|
||||
strcpy(file_sfx, file_tbgz);
|
||||
*file_tbgz = '\0';
|
||||
}
|
||||
|
||||
/* we need to match pattern and suffix seperately, in case
|
||||
* each is a different pattern class (e.g. dewey and
|
||||
* character class (.t[bg]z) */
|
||||
if (pmatch(tmp_pattern, tmp_file)
|
||||
&& pmatch(pat_sfx, file_sfx)) {
|
||||
if (match) {
|
||||
match(dp->d_name, data);
|
||||
/* return value ignored for now */
|
||||
@ -335,9 +393,13 @@ findbestmatchingname_fn(const char *found, char *best)
|
||||
char *found_version, *best_version;
|
||||
char *found_tgz, *best_tgz;
|
||||
char *found_tbz, *best_tbz;
|
||||
char *found_tbgz, *best_tbgz;
|
||||
char found_no_sfx[255];
|
||||
char best_no_sfx[255];
|
||||
|
||||
/* The same suffix-hack-off again, but we can't do it
|
||||
* otherwise without chaning the function call interface
|
||||
*/
|
||||
found_version = strrchr(found, '-') + 1;
|
||||
found_tgz = strstr(found, ".tgz");
|
||||
if (found_tgz) {
|
||||
@ -353,6 +415,13 @@ findbestmatchingname_fn(const char *found, char *best)
|
||||
found_no_sfx[found_tbz-found_version] = '\0';
|
||||
found_version = found_no_sfx;
|
||||
}
|
||||
found_tbgz = strstr(found, ".t[bg]z");
|
||||
if (found_tbgz) {
|
||||
/* strip off any ".t[bg]z" */
|
||||
strncpy(found_no_sfx, found_version, found_tbgz-found_version);
|
||||
found_no_sfx[found_tbgz-found_version] = '\0';
|
||||
found_version = found_no_sfx;
|
||||
}
|
||||
|
||||
best_version=NULL;
|
||||
if (best && best[0] != '\0') {
|
||||
@ -371,6 +440,13 @@ findbestmatchingname_fn(const char *found, char *best)
|
||||
best_no_sfx[best_tbz-best_version] = '\0';
|
||||
best_version = best_no_sfx;
|
||||
}
|
||||
best_tbgz = strstr(best, ".t[bg]z");
|
||||
if (best_tbgz) {
|
||||
/* strip off any ".t[bg]z" */
|
||||
strncpy(best_no_sfx, best_version, best_tbgz-best_version);
|
||||
best_no_sfx[best_tbgz-best_version] = '\0';
|
||||
best_version = best_no_sfx;
|
||||
}
|
||||
}
|
||||
|
||||
if (best == NULL || best[0] == '\0' || deweycmp(found_version, GT, best_version)) {
|
||||
@ -388,7 +464,7 @@ findbestmatchingname_fn(const char *found, char *best)
|
||||
* Returns pointer to pkg name (which can be free(3)ed),
|
||||
* or NULL if no match is available.
|
||||
*/
|
||||
char *
|
||||
char *
|
||||
findbestmatchingname(const char *dir, const char *pattern)
|
||||
{
|
||||
char buf[FILENAME_MAX];
|
||||
|
Loading…
Reference in New Issue
Block a user