From bcedceb0c555fbd119cf1accafc6c73a795719c9 Mon Sep 17 00:00:00 2001 From: joerg Date: Sun, 12 Aug 2007 18:54:08 +0000 Subject: Restore ignorance of entry types for lsbest and lsall for now. The check for already installed packages depends on being able to run them in PKGDB_DIR. This is clearly obnoxius, but leave it for later. --- pkgtools/pkg_install/files/admin/main.c | 10 +++++----- pkgtools/pkg_install/files/lib/file.c | 6 +++--- pkgtools/pkg_install/files/lib/iterate.c | 15 +++++++++------ pkgtools/pkg_install/files/lib/lib.h | 8 ++++---- 4 files changed, 21 insertions(+), 18 deletions(-) (limited to 'pkgtools') diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c index 7e19d487785..dae985dee42 100644 --- a/pkgtools/pkg_install/files/admin/main.c +++ b/pkgtools/pkg_install/files/admin/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.27 2007/08/12 17:51:36 joerg Exp $ */ +/* $NetBSD: main.c,v 1.28 2007/08/12 18:54:08 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -8,7 +8,7 @@ #include #endif #ifndef lint -__RCSID("$NetBSD: main.c,v 1.27 2007/08/12 17:51:36 joerg Exp $"); +__RCSID("$NetBSD: main.c,v 1.28 2007/08/12 18:54:08 joerg Exp $"); #endif /* @@ -708,9 +708,9 @@ main(int argc, char *argv[]) err(EXIT_FAILURE, "getcwd"); if (show_basename_only) - rc = match_local_files(cwd, use_default_sfx, basep, lsbasepattern, NULL); + rc = match_local_files(cwd, use_default_sfx, 1, basep, lsbasepattern, NULL); else - rc = match_local_files(cwd, use_default_sfx, basep, lspattern, cwd); + rc = match_local_files(cwd, use_default_sfx, 1, basep, lspattern, cwd); if (rc == -1) errx(EXIT_FAILURE, "Error from match_local_files(\"%s\", \"%s\", ...)", cwd, basep); @@ -746,7 +746,7 @@ main(int argc, char *argv[]) if (getcwd(cwd, sizeof(cwd)) == NULL) err(EXIT_FAILURE, "getcwd"); - p = find_best_matching_file(cwd, basep, use_default_sfx); + p = find_best_matching_file(cwd, basep, use_default_sfx, 1); if (p) { if (show_basename_only) diff --git a/pkgtools/pkg_install/files/lib/file.c b/pkgtools/pkg_install/files/lib/file.c index bd8e0466a6f..51a5b774f5b 100644 --- a/pkgtools/pkg_install/files/lib/file.c +++ b/pkgtools/pkg_install/files/lib/file.c @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.20 2007/08/12 16:47:17 joerg Exp $ */ +/* $NetBSD: file.c,v 1.21 2007/08/12 18:54:09 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -17,7 +17,7 @@ #if 0 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp"; #else -__RCSID("$NetBSD: file.c,v 1.20 2007/08/12 16:47:17 joerg Exp $"); +__RCSID("$NetBSD: file.c,v 1.21 2007/08/12 18:54:09 joerg Exp $"); #endif #endif @@ -324,7 +324,7 @@ resolvepattern1(const char *name) return tmp; /* return expanded URL w/ corrent pkg */ } else if (ispkgpattern(name)) { - cp = find_best_matching_file(dirname_of(name), basename_of(name), 1); + cp = find_best_matching_file(dirname_of(name), basename_of(name), 1, 0); if (cp) { snprintf(tmp, sizeof(tmp), "%s/%s", dirname_of(name), cp); free(cp); diff --git a/pkgtools/pkg_install/files/lib/iterate.c b/pkgtools/pkg_install/files/lib/iterate.c index 96b0143e7ce..4753b28f407 100644 --- a/pkgtools/pkg_install/files/lib/iterate.c +++ b/pkgtools/pkg_install/files/lib/iterate.c @@ -68,6 +68,7 @@ iterate_pkg_generic_src(int (*matchiter)(const char *, void *), struct pkg_dir_iter_arg { DIR *dirp; int filter_suffix; + int allow_nonfiles; }; static const char * @@ -79,7 +80,8 @@ pkg_dir_iter(void *cookie) while ((dp = readdir(arg->dirp)) != NULL) { #if defined(DT_UNKNOWN) && defined(DT_DIR) - if (dp->d_type != DT_UNKNOWN && dp->d_type != DT_REG) + if (arg->allow_nonfiles == 0 && + dp->d_type != DT_UNKNOWN && dp->d_type != DT_REG) continue; #endif len = strlen(dp->d_name); @@ -98,7 +100,7 @@ pkg_dir_iter(void *cookie) * Call matchiter for every package in the directory. */ int -iterate_local_pkg_dir(const char *dir, int filter_suffix, +iterate_local_pkg_dir(const char *dir, int filter_suffix, int allow_nonfiles, int (*matchiter)(const char *, void *), void *cookie) { struct pkg_dir_iter_arg arg; @@ -108,6 +110,7 @@ iterate_local_pkg_dir(const char *dir, int filter_suffix, return -1; arg.filter_suffix = filter_suffix; + arg.allow_nonfiles = allow_nonfiles; retval = iterate_pkg_generic_src(matchiter, cookie, pkg_dir_iter, &arg); if (closedir(arg.dirp) == -1) @@ -403,7 +406,7 @@ match_best_file(const char *filename, void *cookie) * If no package matched the pattern or an error occured, return NULL. */ char * -find_best_matching_file(const char *dir, const char *pattern, int filter_suffix) +find_best_matching_file(const char *dir, const char *pattern, int filter_suffix, int allow_nonfiles) { struct best_file_match_arg arg; @@ -412,7 +415,7 @@ find_best_matching_file(const char *dir, const char *pattern, int filter_suffix) arg.best_current_match = NULL; arg.best_current_match_filtered = NULL; - if (iterate_local_pkg_dir(dir, filter_suffix, match_best_file, &arg) == -1) { + if (iterate_local_pkg_dir(dir, filter_suffix, allow_nonfiles, match_best_file, &arg) == -1) { warnx("could not process directory"); return NULL; } @@ -472,7 +475,7 @@ match_file_and_call(const char *filename, void *cookie) * callback returned otherwise. */ int -match_local_files(const char *dir, int filter_suffix, const char *pattern, +match_local_files(const char *dir, int filter_suffix, int allow_nonfiles, const char *pattern, int (*cb)(const char *, void *), void *cookie) { struct call_matching_file_arg arg; @@ -482,5 +485,5 @@ match_local_files(const char *dir, int filter_suffix, const char *pattern, arg.cookie = cookie; arg.filter_suffix = filter_suffix; - return iterate_local_pkg_dir(dir, filter_suffix, match_file_and_call, &arg); + return iterate_local_pkg_dir(dir, filter_suffix, allow_nonfiles, match_file_and_call, &arg); } diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h index 5d3acb5b244..c55ffebf825 100644 --- a/pkgtools/pkg_install/files/lib/lib.h +++ b/pkgtools/pkg_install/files/lib/lib.h @@ -1,4 +1,4 @@ -/* $NetBSD: lib.h,v 1.33 2007/08/12 16:47:18 joerg Exp $ */ +/* $NetBSD: lib.h,v 1.34 2007/08/12 18:54:09 joerg Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -330,16 +330,16 @@ void strip_txz(char *, char *, const char *); /* Iterator functions */ int iterate_pkg_generic_src(int (*)(const char *, void *), void *, const char *(*)(void *),void *); -int iterate_local_pkg_dir(const char *, int, int (*)(const char *, void *), +int iterate_local_pkg_dir(const char *, int, int, int (*)(const char *, void *), void *); int iterate_pkg_db(int (*)(const char *, void *), void *); int add_installed_pkgs_by_basename(const char *, lpkg_head_t *); int add_installed_pkgs_by_pattern(const char *, lpkg_head_t *); char *find_best_matching_installed_pkg(const char *); -char *find_best_matching_file(const char *, const char *, int); +char *find_best_matching_file(const char *, const char *, int, int); int match_installed_pkgs(const char *, int (*)(const char *, void *), void *); -int match_local_files(const char *, int, const char *, int (*cb)(const char *, void *), void *); +int match_local_files(const char *, int, int, const char *, int (*cb)(const char *, void *), void *); /* File */ Boolean fexists(const char *); -- cgit v1.2.3