diff options
author | pav <pav@FreeBSD.org> | 2008-05-03 22:56:50 +0000 |
---|---|---|
committer | pav <pav@FreeBSD.org> | 2008-05-03 22:56:50 +0000 |
commit | f6342a8cc70520205466101de2fc3225e5c9ab2c (patch) | |
tree | 047e0d070e77398a2c7167602f4bfa0c7a91be2a /usr.sbin/pkg_install/lib | |
parent | 0cabcd8279358de2fe1c18b8f6403831e37f9967 (diff) | |
download | FreeBSD-src-f6342a8cc70520205466101de2fc3225e5c9ab2c.zip FreeBSD-src-f6342a8cc70520205466101de2fc3225e5c9ab2c.tar.gz |
- Restore functionality broken in previous commit; we need to be able to report
multiple installed packages with the same PKGORIGIN.
Reported by: marcus
MFC after: 1 month
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 2 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/match.c | 21 |
2 files changed, 13 insertions, 10 deletions
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 3e0ce7e..7aea8d0 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -225,7 +225,7 @@ int real_main(int, char **); /* Query installed packages */ char **matchinstalled(match_t, char **, int *); char **matchbyorigin(const char *, int *); -char **matchallbyorigin(const char **, int *); +char ***matchallbyorigin(const char **, int *); int isinstalledpkg(const char *name); int pattern_match(match_t MatchType, char *pattern, const char *pkgname); diff --git a/usr.sbin/pkg_install/lib/match.c b/usr.sbin/pkg_install/lib/match.c index 885533f..1f8b02a 100644 --- a/usr.sbin/pkg_install/lib/match.c +++ b/usr.sbin/pkg_install/lib/match.c @@ -237,10 +237,11 @@ pattern_match(match_t MatchType, char *pattern, const char *pkgname) * Synopsis is similar to matchinstalled(), but use origin * as a key for matching packages. */ -char ** +char *** matchallbyorigin(const char **origins, int *retval) { - char **installed, **allorigins = NULL, **matches = NULL; + char **installed, **allorigins = NULL; + char ***matches = NULL; int i, j; if (retval != NULL) @@ -299,16 +300,20 @@ matchallbyorigin(const char **origins, int *retval) /* Resolve origins into package names, retaining the sequence */ for (i = 0; origins[i] != NULL; i++) { matches = realloc(matches, (i + 1) * sizeof(*matches)); - matches[i] = NULL; + struct store *store = NULL; + store = storecreate(store); for (j = 0; installed[j] != NULL; j++) { if (allorigins[j]) { if (csh_match(origins[i], allorigins[j], FNM_PATHNAME) == 0) { - matches[i] = installed[j]; - break; + storeappend(store, installed[j]); } } } + if (store->used == 0) + matches[i] = NULL; + else + matches[i] = store->store; } if (allorigins) { @@ -329,16 +334,14 @@ char ** matchbyorigin(const char *origin, int *retval) { const char *origins[2]; - char **tmp; + char ***tmp; origins[0] = origin; origins[1] = NULL; tmp = matchallbyorigin(origins, retval); if (tmp && tmp[0]) { - tmp = realloc(tmp, 2 * sizeof(*tmp)); - tmp[1] = NULL; - return tmp; + return tmp[0]; } else { return NULL; } |