Date: Wed, 22 Oct 2008 17:52:25 GMT From: Anders Nore <andenore@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 151735 for review Message-ID: <200810221752.m9MHqPgV055152@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <bsd.own.mk> -SUBDIR= lib add create delete info updating version convert +SUBDIR= lib add create delete info updating version convert upgrade .include <bsd.subdir.mk> @@ -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 <sys/cdefs.h> -__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 <sys/param.h> #include <sys/utsname.h> @@ -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 <time.h> #include <sys/ioctl.h> +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; +} + +
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810221752.m9MHqPgV055152>