summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2001-03-14 19:46:43 +0000
committersobomax <sobomax@FreeBSD.org>2001-03-14 19:46:43 +0000
commitdb4760d36b7961c113a683d669802cb03d229ac2 (patch)
treef1281bba37f5f21f3df198f5810f5dc4bbe10c9c /usr.sbin/pkg_install/lib
parentfc1bb300608269c06d54be2ba82309a451ef387a (diff)
downloadFreeBSD-src-db4760d36b7961c113a683d669802cb03d229ac2.zip
FreeBSD-src-db4760d36b7961c113a683d669802cb03d229ac2.tar.gz
When matching installed packages against glob keep track of which patterns
actually triggered a match and which did not, and add patterns that didn't into resulting list, so caller will have a chance to notify user that package isn't installed. This should fix current, POLA-breaking behaviour when user doesn't receive a notification if he specifies several packages, some of which aren't installed.
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/match.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/usr.sbin/pkg_install/lib/match.c b/usr.sbin/pkg_install/lib/match.c
index 917ef67..2bcae2a 100644
--- a/usr.sbin/pkg_install/lib/match.c
+++ b/usr.sbin/pkg_install/lib/match.c
@@ -58,12 +58,13 @@ static int fname_cmp(const FTSENT **, const FTSENT **);
char **
matchinstalled(match_t MatchType, char **patterns, int *retval)
{
- int i, errcode;
+ int i, errcode, len;
char *tmp, *matched;
char *paths[2];
static struct store *store = NULL;
FTS *ftsp;
FTSENT *f;
+ Boolean *lmatched;
if (store == NULL) {
store = malloc(sizeof *store);
@@ -95,6 +96,18 @@ matchinstalled(match_t MatchType, char **patterns, int *retval)
/* Not reached */
}
+ /* Count number of patterns */
+ for (len = 0; patterns[len]; len++) {}
+ lmatched = alloca(sizeof(*lmatched) * len);
+ if (lmatched == NULL) {
+ warnx("%s(): alloca() failed", __FUNCTION__);
+ if (retval != NULL)
+ *retval = 1;
+ return NULL;
+ }
+ for (i = 0; i < len; i++)
+ lmatched[i] = FALSE;
+
paths[0] = tmp;
paths[1] = NULL;
ftsp = fts_open(paths, FTS_LOGICAL | FTS_NOCHDIR | FTS_NOSTAT, fname_cmp);
@@ -117,8 +130,10 @@ matchinstalled(match_t MatchType, char **patterns, int *retval)
}
break;
case MATCH_GLOB:
- if (fnmatch(patterns[i], f->fts_name, 0) == 0)
+ if (fnmatch(patterns[i], f->fts_name, 0) == 0) {
matched = f->fts_name;
+ lmatched[i] = TRUE;
+ }
break;
default:
break;
@@ -139,6 +154,12 @@ matchinstalled(match_t MatchType, char **patterns, int *retval)
fts_close(ftsp);
}
+ if (MatchType == MATCH_GLOB) {
+ for (i = 0; i < len; i++)
+ if (lmatched[i] == FALSE)
+ storeappend(store, patterns[i]);
+ }
+
if (store->used == 0)
return NULL;
else
OpenPOWER on IntegriCloud