diff options
author | Pav Lucistnik <pav@FreeBSD.org> | 2008-04-11 08:26:06 +0000 |
---|---|---|
committer | Pav Lucistnik <pav@FreeBSD.org> | 2008-04-11 08:26:06 +0000 |
commit | 42b1030bbdd02d8264a87179c9465d834ff5a624 (patch) | |
tree | 10d3af807888e075cd1a6aec7853f38e50370ba8 /usr.sbin/pkg_install/add/perform.c | |
parent | 44b779b337e62acfcd4dda247fd81a102903f116 (diff) |
Optimize package registration/deregistration. Previously, when looking up the
package name for the origin of a dependency, all entries in /var/db/pkg were
traversed for each dependency of added/removed package. Now, gather all the
origins first, then do the lookup in a single pass over /var/db/pkg.
This should provide a major speedup for packages with hundreds of dependencies.
Submitted by: rdivacky (earlier version)
MFC after: 1 month
Notes
Notes:
svn path=/head/; revision=178103
Diffstat (limited to 'usr.sbin/pkg_install/add/perform.c')
-rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 86 |
1 files changed, 62 insertions, 24 deletions
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 3b3472856795..3d86a9d1aa3b 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -452,6 +452,8 @@ pkg_do(char *pkg) /* Time to record the deed? */ if (!NoRecord && !Fake) { char contents[FILENAME_MAX]; + char **depnames = NULL, **deporigins = NULL, **depmatches; + int i, dep_count = 0; FILE *contfile; if (getuid() != 0) @@ -495,8 +497,7 @@ pkg_do(char *pkg) write_plist(&Plist, contfile); fclose(contfile); for (p = Plist.head; p ; p = p->next) { - char *deporigin, **depnames; - int i; + char *deporigin; if (p->type != PLIST_PKGDEP) continue; @@ -509,32 +510,69 @@ pkg_do(char *pkg) printf(".\n"); } - depnames = (deporigin != NULL) ? matchbyorigin(deporigin, NULL) : - NULL; - if (depnames == NULL) { - depnames = alloca(sizeof(*depnames) * 2); - depnames[0] = p->name; - depnames[1] = NULL; + if (deporigin) { + /* Defer to origin lookup */ + depnames = realloc(depnames, (dep_count + 1) * sizeof(*depnames)); + depnames[dep_count] = p->name; + deporigins = realloc(deporigins, (dep_count + 2) * sizeof(*deporigins)); + deporigins[dep_count] = deporigin; + deporigins[dep_count + 1] = NULL; + dep_count++; + } else { + /* No origin recorded, try to register on literal package name */ + sprintf(contents, "%s/%s/%s", LOG_DIR, p->name, + REQUIRED_BY_FNAME); + contfile = fopen(contents, "a"); + if (!contfile) { + warnx("can't open dependency file '%s'!\n" + "dependency registration is incomplete", contents); + } else { + fprintf(contfile, "%s\n", Plist.name); + if (fclose(contfile) == EOF) { + warnx("cannot properly close file %s", contents); + } + } } - if(!IgnoreDeps){ - for (i = 0; depnames[i] != NULL; i++) { - sprintf(contents, "%s/%s/%s", LOG_DIR, depnames[i], - REQUIRED_BY_FNAME); - if (strcmp(p->name, depnames[i]) != 0) - warnx("warning: package '%s' requires '%s', but '%s' " - "is installed", Plist.name, p->name, depnames[i]); - contfile = fopen(contents, "a"); - if (!contfile) - warnx("can't open dependency file '%s'!\n" - "dependency registration is incomplete", contents); - else { - fprintf(contfile, "%s\n", Plist.name); - if (fclose(contfile) == EOF) - warnx("cannot properly close file %s", contents); + } + if (dep_count > 0) { + depmatches = matchallbyorigin((const char **)deporigins, NULL); + free(deporigins); + if (!IgnoreDeps && depmatches) { + for (i = 0; i < dep_count; i++) { + if (depmatches[i]) { + /* Origin looked up */ + sprintf(contents, "%s/%s/%s", LOG_DIR, depmatches[i], + REQUIRED_BY_FNAME); + if (depnames[i] && strcmp(depnames[i], depmatches[i]) != 0) + warnx("warning: package '%s' requires '%s', but '%s' " + "is installed", Plist.name, depnames[i], depmatches[i]); + contfile = fopen(contents, "a"); + if (!contfile) { + warnx("can't open dependency file '%s'!\n" + "dependency registration is incomplete", contents); + } else { + fprintf(contfile, "%s\n", Plist.name); + if (fclose(contfile) == EOF) + warnx("cannot properly close file %s", contents); + } + } else if (depnames[i]) { + /* No package present with this origin, try literal package name */ + sprintf(contents, "%s/%s/%s", LOG_DIR, depnames[i], + REQUIRED_BY_FNAME); + contfile = fopen(contents, "a"); + if (!contfile) { + warnx("can't open dependency file '%s'!\n" + "dependency registration is incomplete", contents); + } else { + fprintf(contfile, "%s\n", Plist.name); + if (fclose(contfile) == EOF) { + warnx("cannot properly close file %s", contents); + } + } + } } } } - } if (Verbose) printf("Package %s registered in %s\n", Plist.name, LogDir); } |