From owner-p4-projects@FreeBSD.ORG Wed Oct 22 17:52:26 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5A5C71065673; Wed, 22 Oct 2008 17:52:26 +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 1E2FF106566C for ; Wed, 22 Oct 2008 17:52:26 +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 0BF828FC1C for ; Wed, 22 Oct 2008 17:52:26 +0000 (UTC) (envelope-from andenore@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m9MHqPlW055154 for ; Wed, 22 Oct 2008 17:52:25 GMT (envelope-from andenore@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m9MHqPgV055152 for perforce@freebsd.org; Wed, 22 Oct 2008 17:52:25 GMT (envelope-from andenore@FreeBSD.org) Date: Wed, 22 Oct 2008 17:52:25 GMT Message-Id: <200810221752.m9MHqPgV055152@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 151735 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: Wed, 22 Oct 2008 17:52:26 -0000 http://perforce.freebsd.org/chv.cgi?CH=151735 Change 151735 by andenore@andenore_laptop on 2008/10/22 17:51:56 Some edits, integrate, and testing binary package upgrading. Affected files ... .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#6 integrate .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#11 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#17 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/url.c#8 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/upgrade/Makefile#1 add .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/upgrade/main.c#1 add Differences ... ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/Makefile#5 (text+ko) ==== @@ -2,7 +2,7 @@ .include -SUBDIR= lib add create delete info updating version convert +SUBDIR= lib add create delete info updating version convert upgrade .include @@ -19,4 +19,4 @@ test: - ./test.sh zip.tbz+ ./test.sh zip.tbz ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/main.c#6 (text+ko) ==== @@ -19,7 +19,7 @@ */ #include -__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/main.c,v 1.78 2008/06/16 23:41:11 flz Exp $"); +__FBSDID("$FreeBSD: src/usr.sbin/pkg_install/add/main.c,v 1.79 2008/10/17 15:10:45 brooks Exp $"); #include #include @@ -266,7 +266,7 @@ } } /* If no packages, yelp */ - else if (!ch) { + if (!ch) { warnx("missing package name(s)"); usage(); } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/perform.c#11 (text+ko) ==== @@ -34,6 +34,7 @@ static int pkg_do(char *); static int sanity_check(char *); +static char *check_dependencies(const char *, Package *); static char LogDir[FILENAME_MAX]; static int zapLogDir; /* Should we delete LogDir? */ char wd[FILENAME_MAX]; @@ -292,6 +293,13 @@ warnx("-f specified; proceeding anyway"); } + char *tmpName; + if ((tmpName = check_dependencies(pkg, &Plist)) != NULL) { + warnx("Cannot add package `%s', package don't exist %s", tmpName, Force ? "(but proceeding anyway)" : ""); + if (!Force) + goto bomb; + } + /* Now check the packing list for dependencies */ for (p = Plist.head; p ; p = p->next) { char *deporigin; @@ -311,6 +319,7 @@ printf(".\n"); } + /* Check if we have to add the dependency */ if (isinstalledpkg(p->name) <= 0 && !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { char path[FILENAME_MAX], *cp = NULL; @@ -687,6 +696,34 @@ return code; } +/* Returns NULL on success */ +static char * +check_dependencies(const char *base, Package *plist) +{ + PackingList p; + static char retval[FILENAME_MAX]; + + for (p = Plist.head; p ; p = p->next) { + char *deporigin; + + if (p->type != PLIST_PKGDEP) + continue; + + deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; + + /* Check if we have to add the dependency */ + if (isinstalledpkg(p->name) <= 0 && + !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { + if (!fileExistsURL(base, p->name)) { + strncpy(retval, p->name, sizeof(retval)); + return retval; + } + } + } + + return NULL; +} + void cleanup(int sig) { ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#17 (text+ko) ==== @@ -197,6 +197,7 @@ Boolean issymlink(const char *); Boolean isURL(const char *); char *fileGetURL(const char *, const char *, int); +Boolean fileExistsURL(const char *base, const char *spec); char *fileFindByPath(const char *, const char *); char *fileGetContents(const char *); void write_file(const char *, const char *); ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/url.c#8 (text+ko) ==== @@ -30,6 +30,9 @@ #include #include +static char *formatURL(const char *, const char *, char *); + + /* * Try and fetch a file by URL, returning the directory name for where * it's unpacked, if successful. @@ -59,48 +62,8 @@ bzero(&oldtime, sizeof(oldtime)); rp = NULL; - /* Special tip that sysinstall left for us */ - hint = getenv("PKG_ADD_BASE"); - if (!isURL(spec)) { - if (!base && !hint) - return NULL; - /* - * We've been given an existing URL (that's known-good) and now we need - * to construct a composite one out of that and the basename we were - * handed as a dependency. - */ - if (base) { - strcpy(fname, base); - /* - * Advance back two slashes to get to the root of the package - * hierarchy - */ - cp = strrchr(fname, '/'); - if (cp) { - *cp = '\0'; /* chop name */ - cp = strrchr(fname, '/'); - } - if (cp) { - *(cp + 1) = '\0'; - strcat(cp, "All/"); - strcat(cp, spec); - strcat(cp, ".tbz"); - } - else - return NULL; - } - else { - /* - * Otherwise, we've been given an environment variable hinting - * at the right location from sysinstall - */ - strcpy(fname, hint); - strcat(fname, spec); - strcat(fname, ".tbz"); - } - } - else - strcpy(fname, spec); + + formatURL(base, spec, fname); if (keep_package) { tmp = getenv("PKGDIR"); @@ -231,3 +194,85 @@ printf("%*s \n", cols-1, "Done"); return rp; } + +/* + * Checks if a file exists + */ + +Boolean +fileExistsURL(const char *base, const char *spec) +{ + FILE *fp; + Boolean retval; + char fname[FILENAME_MAX]; + + formatURL(base, spec, fname); + + if ((fp = fetchGetURL(fname, NULL)) == NULL) { + if (Verbose) + warnx("Cannot get the file: %s", fname); + retval = FALSE; + } else { + retval = TRUE; + } + + if (fp) + fclose(fp); + return retval; +} + +/* + * Format base and spec into an url used by fetchGetURL and fetchStatURL + */ +static char * +formatURL(const char *base, const char *spec, char *result) +{ + char *hint, *cp; + + /* Special tip that sysinstall left for us */ + hint = getenv("PKG_ADD_BASE"); + if (!isURL(spec)) { + if (!base && !hint) + return FALSE; + /* + * We've been given an existing URL (that's known-good) and now we need + * to construct a composite one out of that and the basename we were + * handed as a dependency. + */ + if (base) { + strcpy(result, base); + /* + * Advance back two slashes to get to the root of the package + * hierarchy + */ + cp = strrchr(result, '/'); + if (cp) { + *cp = '\0'; /* chop name */ + cp = strrchr(result, '/'); + } + if (cp) { + *(cp + 1) = '\0'; + strcat(cp, "All/"); + strcat(cp, spec); + strcat(cp, ".tbz"); + } + else + return FALSE; + } + else { + /* + * Otherwise, we've been given an environment variable hinting + * at the right location from sysinstall + */ + strcpy(result, hint); + strcat(result, spec); + strcat(result, ".tbz"); + } + } + else + strcpy(result, spec); + + return result; +} + +