pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files - Introduce find_best_match...
details: https://anonhg.NetBSD.org/pkgsrc/rev/0b831ed42aaa
branches: trunk
changeset: 532144:0b831ed42aaa
user: joerg <joerg%pkgsrc.org@localhost>
date: Sun Aug 12 16:47:17 2007 +0000
description:
- Introduce find_best_matching_file and match_local_files. This replace
the functionality offered by findmatchingname and findbestmatching
name. They optionally strip the suffix from the filename before
matching it, instead of modifying the pattern directly.
Drop the old functions.
- Fix a bug in pkg_order where the version strings where inverted
- Make pkg_admin lsbest and lsall use the new functions.
- Make ftpio use pkg_order directly.
Bump version to 20070812.
diffstat:
pkgtools/pkg_install/files/admin/main.c | 32 ++---
pkgtools/pkg_install/files/lib/file.c | 7 +-
pkgtools/pkg_install/files/lib/ftpio.c | 33 ++--
pkgtools/pkg_install/files/lib/iterate.c | 176 ++++++++++++++++++++++++++++-
pkgtools/pkg_install/files/lib/lib.h | 15 +-
pkgtools/pkg_install/files/lib/opattern.c | 10 +-
pkgtools/pkg_install/files/lib/str.c | 138 +-----------------------
pkgtools/pkg_install/files/lib/version.h | 4 +-
8 files changed, 214 insertions(+), 201 deletions(-)
diffs (truncated from 719 to 300 lines):
diff -r 1c6a56ee4053 -r 0b831ed42aaa pkgtools/pkg_install/files/admin/main.c
--- a/pkgtools/pkg_install/files/admin/main.c Sun Aug 12 15:17:43 2007 +0000
+++ b/pkgtools/pkg_install/files/admin/main.c Sun Aug 12 16:47:17 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.25 2007/08/10 21:18:31 joerg Exp $ */
+/* $NetBSD: main.c,v 1.26 2007/08/12 16:47:17 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.25 2007/08/10 21:18:31 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.26 2007/08/12 16:47:17 joerg Exp $");
#endif
/*
@@ -436,17 +436,17 @@
}
static int
-lspattern_fn(const char *pattern, const char *pkg, void *vp)
+lspattern(const char *pkg, void *vp)
{
- char *data = vp;
- printf("%s/%s\n", data, pkg);
+ const char *dir = vp;
+ printf("%s/%s\n", dir, pkg);
return 0;
}
static int
-lsbasepattern_fn(const char *pattern, const char *pkg, void *vp)
+lsbasepattern(const char *pkg, void *vp)
{
- printf("%s\n", pkg);
+ puts(pkg);
return 0;
}
@@ -695,11 +695,9 @@
int rc;
const char *basep, *dir;
char cwd[MaxPathSize];
- char base[MaxPathSize];
dir = lsdirp ? lsdirp : dirname_of(*argv);
basep = basename_of(*argv);
- snprintf(base, sizeof(base), "%s%s", basep, sfx);
fchdir(saved_wd);
rc = chdir(dir);
@@ -710,11 +708,11 @@
err(EXIT_FAILURE, "getcwd");
if (show_basename_only)
- rc = findmatchingname(cwd, base, lsbasepattern_fn, cwd);
+ rc = match_local_files(cwd, use_default_sfx, basep, lsbasepattern, NULL);
else
- rc = findmatchingname(cwd, base, lspattern_fn, cwd);
+ rc = match_local_files(cwd, use_default_sfx, basep, lspattern, cwd);
if (rc == -1)
- errx(EXIT_FAILURE, "Error in findmatchingname(\"%s\", \"%s\", ...)",
+ errx(EXIT_FAILURE, "Error from match_local_files(\"%s\", \"%s\", ...)",
cwd, base);
argv++;
@@ -734,24 +732,22 @@
while (*argv != NULL) {
/* args specified */
- int rc;
const char *basep, *dir;
char cwd[MaxPathSize];
- char base[MaxPathSize];
char *p;
dir = lsdirp ? lsdirp : dirname_of(*argv);
basep = basename_of(*argv);
- snprintf(base, sizeof(base), "%s%s", basep, sfx);
fchdir(saved_wd);
- rc = chdir(dir);
- if (rc == -1)
+ if (chdir(dir) == -1)
err(EXIT_FAILURE, "Cannot chdir to %s", dir);
if (getcwd(cwd, sizeof(cwd)) == NULL)
err(EXIT_FAILURE, "getcwd");
- p = findbestmatchingname(cwd, base);
+
+ p = find_best_matching_file(cwd, basep, use_default_sfx);
+
if (p) {
if (show_basename_only)
printf("%s\n", p);
diff -r 1c6a56ee4053 -r 0b831ed42aaa pkgtools/pkg_install/files/lib/file.c
--- a/pkgtools/pkg_install/files/lib/file.c Sun Aug 12 15:17:43 2007 +0000
+++ b/pkgtools/pkg_install/files/lib/file.c Sun Aug 12 16:47:17 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: file.c,v 1.19 2007/04/16 12:55:35 joerg Exp $ */
+/* $NetBSD: file.c,v 1.20 2007/08/12 16:47:17 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.19 2007/04/16 12:55:35 joerg Exp $");
+__RCSID("$NetBSD: file.c,v 1.20 2007/08/12 16:47:17 joerg Exp $");
#endif
#endif
@@ -324,8 +324,7 @@
return tmp; /* return expanded URL w/ corrent pkg */
}
else if (ispkgpattern(name)) {
- cp = findbestmatchingname(
- dirname_of(name), basename_of(name));
+ cp = find_best_matching_file(dirname_of(name), basename_of(name), 1);
if (cp) {
snprintf(tmp, sizeof(tmp), "%s/%s", dirname_of(name), cp);
free(cp);
diff -r 1c6a56ee4053 -r 0b831ed42aaa pkgtools/pkg_install/files/lib/ftpio.c
--- a/pkgtools/pkg_install/files/lib/ftpio.c Sun Aug 12 15:17:43 2007 +0000
+++ b/pkgtools/pkg_install/files/lib/ftpio.c Sun Aug 12 16:47:17 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ftpio.c,v 1.23 2007/07/20 22:22:53 joerg Exp $ */
+/* $NetBSD: ftpio.c,v 1.24 2007/08/12 16:47:18 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: ftpio.c,v 1.23 2007/07/20 22:22:53 joerg Exp $");
+__RCSID("$NetBSD: ftpio.c,v 1.24 2007/08/12 16:47:18 joerg Exp $");
#endif
/*-
@@ -655,10 +655,12 @@
char *s, buf[MaxPathSize];
char tmpname[MaxPathSize];
char best[MaxPathSize];
+ char s_best[MaxPathSize];
int rc, got_list, tfd, retry_tbz;
retry_tbz = 0;
best[0]='\0';
+ s_best[0]='\0';
rc = ftp_start(base);
if (rc == -1) {
@@ -714,7 +716,6 @@
}
if (got_list == 1 && access(tmpname, R_OK)==0) {
- int matches;
FILE *f;
char filename[MaxPathSize];
@@ -724,7 +725,6 @@
unlink(tmpname); /* remove clutter */
return NULL;
}
- matches=0;
/* The following loop is basically the same as the readdir() loop
* in findmatchingname() */
while (fgets(filename, sizeof(filename), f)) {
@@ -742,22 +742,21 @@
strip_txz(s_filename, NULL, filename);
strip_txz(s_pattern, NULL, pattern);
- if (pkg_match(s_pattern, s_filename)) {
- matches++;
-
- /* compare findbestmatchingname() */
- findbestmatchingname_fn(pattern, filename, best);
+ if (pkg_order(s_pattern, s_filename,
+ s_best[0] != '\0' ? s_best : NULL) == 1) {
+ strlcpy(s_best, s_filename, sizeof(s_best));
+ strlcpy(best, filename, sizeof(best));
}
}
(void) fclose(f);
-
- if (matches == 0 && Verbose)
- warnx("nothing appropriate found");
}
if (retry_tbz)
goto retry_with_tbz;
+ if (best[0] == '\0' && Verbose)
+ warnx("nothing appropriate found");
+
unlink(tmpname);
if (best[0] == '\0')
@@ -771,6 +770,7 @@
http_expand_URL(const char *base, char *pattern)
{
char best[MaxPathSize];
+ char s_best[MaxPathSize];
char line[BUFSIZ];
char filename[MaxPathSize];
FILE *fp;
@@ -779,6 +779,7 @@
pid_t pid;
*best = '\0';
+ *s_best = '\0';
/* Set up a pipe for getting the file list */
if (pipe(pipefds) == -1) {
@@ -828,10 +829,10 @@
offset += len;
strip_txz(s_filename, NULL, filename);
- if (pkg_match(s_pattern, s_filename)) {
- /* compare findbestmatchingname() */
- findbestmatchingname_fn(pattern,
- filename, best);
+ if (pkg_order(s_pattern, s_filename,
+ *s_best != '\0' ? s_best : NULL) == 1) {
+ strlcpy(best, filename, sizeof(best));
+ strlcpy(s_best, s_filename, sizeof(best));
}
}
}
diff -r 1c6a56ee4053 -r 0b831ed42aaa pkgtools/pkg_install/files/lib/iterate.c
--- a/pkgtools/pkg_install/files/lib/iterate.c Sun Aug 12 15:17:43 2007 +0000
+++ b/pkgtools/pkg_install/files/lib/iterate.c Sun Aug 12 16:47:17 2007 +0000
@@ -65,14 +65,19 @@
return retval;
}
+struct pkg_dir_iter_arg {
+ DIR *dirp;
+ int filter_suffix;
+};
+
static const char *
pkg_dir_iter(void *cookie)
{
- DIR *dirp = cookie;
+ struct pkg_dir_iter_arg *arg = cookie;
struct dirent *dp;
size_t len;
- while ((dp = readdir(dirp)) != NULL) {
+ while ((dp = readdir(arg->dirp)) != NULL) {
#if defined(DT_UNKNOWN) && defined(DT_DIR)
if (dp->d_type != DT_UNKNOWN && dp->d_type != DT_REG)
continue;
@@ -81,7 +86,8 @@
/* .tbz or .tgz suffix length + some prefix*/
if (len < 5)
continue;
- if (memcmp(dp->d_name + len - 4, ".tgz", 4) == 0 ||
+ if (arg->filter_suffix == 0 ||
+ memcmp(dp->d_name + len - 4, ".tgz", 4) == 0 ||
memcmp(dp->d_name + len - 4, ".tbz", 4) == 0)
return dp->d_name;
}
@@ -92,18 +98,19 @@
* Call matchiter for every package in the directory.
*/
int
-iterate_local_pkg_dir(const char *dir, int (*matchiter)(const char *, void *),
- void *cookie)
+iterate_local_pkg_dir(const char *dir, int filter_suffix,
+ int (*matchiter)(const char *, void *), void *cookie)
{
- DIR *dirp;
+ struct pkg_dir_iter_arg arg;
int retval;
- if ((dirp = opendir(dir)) == NULL)
+ if ((arg.dirp = opendir(dir)) == NULL)
return -1;
- retval = iterate_pkg_generic_src(matchiter, cookie, pkg_dir_iter, dirp);
+ arg.filter_suffix = filter_suffix;
+ retval = iterate_pkg_generic_src(matchiter, cookie, pkg_dir_iter, &arg);
- if (closedir(dirp) == -1)
+ if (closedir(arg.dirp) == -1)
return -1;
return retval;
}
@@ -326,3 +333,154 @@
return iterate_pkg_db(match_and_call, &arg);
}
+
+struct best_file_match_arg {
Home |
Main Index |
Thread Index |
Old Index