From owner-p4-projects@FreeBSD.ORG Fri Jul 18 11:35:42 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1A5681065673; Fri, 18 Jul 2008 11:35:42 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D1C081065677 for ; Fri, 18 Jul 2008 11:35:41 +0000 (UTC) (envelope-from andenore@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id AF63D8FC12 for ; Fri, 18 Jul 2008 11:35:41 +0000 (UTC) (envelope-from andenore@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m6IBZfWb051110 for ; Fri, 18 Jul 2008 11:35:41 GMT (envelope-from andenore@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m6IBZf8r051105 for perforce@freebsd.org; Fri, 18 Jul 2008 11:35:41 GMT (envelope-from andenore@FreeBSD.org) Date: Fri, 18 Jul 2008 11:35:41 GMT Message-Id: <200807181135.m6IBZf8r051105@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andenore@FreeBSD.org using -f From: Anders Nore To: Perforce Change Reviews Cc: Subject: PERFORCE change 145423 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jul 2008 11:35:42 -0000 http://perforce.freebsd.org/chv.cgi?CH=145423 Change 145423 by andenore@andenore_laptop on 2008/07/18 11:35:39 Made function fix_dependencies(pkgname) in lib/deps.c and pkg_create -O now fixes dependencies. Affected files ... .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#6 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#7 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#2 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/deps.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#10 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#6 edit Differences ... ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#6 (text+ko) ==== @@ -492,47 +492,7 @@ * Reconstructs +REQUIRED_BY file for the package to be installed in * case it has been removed earlier (e.g. pkg_delete -f) */ - if (Verbose) - printf("Recording existing dependency's on %s\n", Plist.name); - int errcode; - matched = matchinstalled(MATCH_ALL, NULL, &errcode); - for (i = 0; matched[i] != NULL; i++) { - FILE *fp; - Package nplist; - char path[PATH_MAX]; - - /* Skip this package */ - if (strcmp(matched[i], Plist.name) == 0) - continue; - - snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, matched[i], CONTENTS_FNAME); - if ((fp = fopen(path, "r")) == NULL) { - warn("Could not open %s for reading", path); - continue; - } - read_plist(&nplist, fp); - fclose(fp); - - for (p = nplist.head; p != nplist.tail; p = p->next) { - if (p->type != PLIST_PKGDEP) - continue; - if (strcmp(p->name, Plist.name) == 0) { - /* Register this package in REQUIRED_BY_FNAME */ - snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, Plist.name, REQUIRED_BY_FNAME); - if ((fp = fopen(path, "a")) == NULL) { - warn("Could not open %s", path); - continue; - } - fprintf(fp, "%s\n", nplist.name); - fclose(fp); - if (Verbose) - printf("\t %s depends on %s (REGISTERED)\n", p->name, Plist.name); - } - } - free_plist(&nplist); - free(matched[i]); - } - free(matched); + fix_dependencies(Plist.name); /* Make sure pkg_info can read the entry */ ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/create/perform.c#7 (text+ko) ==== @@ -244,9 +244,13 @@ if (PlistOnly) { if (openDatabase(O_CREAT | O_RDWR)) err("Could not open database: %s", DBCACHE_FILE); - - plist_add_installtime(&plist); - check_list(home, &plist); + Boolean v = Verbose; + Verbose = FALSE; + fix_dependencies(plist.name); + Verbose = v; + + plist_add_installtime(&plist); + check_list(home, &plist); write_plist(&plist, stdout); int retval = cache_plist(&plist, FALSE); ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#2 (text+ko) ==== @@ -2,8 +2,9 @@ LIB= install INTERNALLIB= -SRCS= file.c msg.c plist.c str.c exec.c global.c pen.c match.c \ - deps.c version.c pkgwrap.c url.c +SRCS= file.c msg.c plist.c str.c exec.c global.c pen.c database.c match.c \ + deps.c version.c pkgwrap.c url.c +CFLAGS= -g WARNS?= 3 WFORMAT?= 1 ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/deps.c#3 (text+ko) ==== @@ -244,3 +244,59 @@ return retval; } + +/* + * Fixes dependencies on the package with name pkgname. + * It scans the installed packages, searches for @pkgdep in the +CONTENS file + * and see if that matches the given pkgname, if it does then register the + * installed package in pkgname's +REQUIRED_BY file. + */ +void +fix_dependencies(char *pkgname) +{ + int i; + char **matched; + PackingList p = NULL; + if (Verbose) + printf("Recording existing dependency's on %s\n", pkgname); + int errcode; + matched = matchinstalled(MATCH_ALL, NULL, &errcode); + for (i = 0; matched[i] != NULL; i++) { + FILE *fp; + Package nplist; + char path[PATH_MAX]; + + bzero(&nplist, sizeof(nplist)); + /* Skip this package */ + if (strcmp(matched[i], pkgname) == 0) + continue; + + snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, matched[i], CONTENTS_FNAME); + if ((fp = fopen(path, "r")) == NULL) { + warn("fix_dependencies: Could not open %s for reading", path); + continue; + } + read_plist(&nplist, fp); + fclose(fp); + + for (p = nplist.head; p != nplist.tail; p = p->next) { + if (p->type != PLIST_PKGDEP) + continue; + if (strcmp(p->name, pkgname) == 0) { + /* Register this package in REQUIRED_BY_FNAME */ + snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, pkgname, REQUIRED_BY_FNAME); + if ((fp = fopen(path, "a")) == NULL) { + warn("fix_dependencies: Could not open %s", path); + continue; + } + fprintf(fp, "%s\n", nplist.name); + fclose(fp); + if (Verbose) + printf("\t %s depends on %s\n", nplist.name, pkgname); + } + } + free_plist(&nplist); + free(matched[i]); + } + free(matched); +} ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#10 (text+ko) ==== @@ -246,6 +246,7 @@ int sortdeps(char **); int chkifdepends(const char *, const char *); int requiredby(const char *, struct reqr_by_head **, Boolean, Boolean); +void fix_dependencies(char *pkgname); /* Version */ int verscmp(Package *, int, int); ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/plist.c#6 (text+ko) ==== @@ -310,10 +310,11 @@ } if (cmd == PLIST_COMMENT && sscanf(cp, "DATE:%d\n", &date) == 1) { pkg->datetime = date; + goto bottom; } bottom: - add_plist(pkg, cmd, cp); + add_plist(pkg, cmd, cp); } } @@ -437,7 +438,7 @@ switch (p->type) { case PLIST_NAME: name = p->name; - if (dbRemove(name) != 0) + if (dbRemove(name) == -1) warnx("%s: Failed to remove entry %s from db\n", __func__, name); break;