From owner-p4-projects@FreeBSD.ORG Sun Aug 3 21:53:47 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B1B211065675; Sun, 3 Aug 2008 21:53:47 +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 766D1106566B for ; Sun, 3 Aug 2008 21:53:47 +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 623A98FC1C for ; Sun, 3 Aug 2008 21:53:47 +0000 (UTC) (envelope-from andenore@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m73LrlWW019706 for ; Sun, 3 Aug 2008 21:53:47 GMT (envelope-from andenore@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m73Lrlwd019704 for perforce@freebsd.org; Sun, 3 Aug 2008 21:53:47 GMT (envelope-from andenore@FreeBSD.org) Date: Sun, 3 Aug 2008 21:53:47 GMT Message-Id: <200808032153.m73Lrlwd019704@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 146568 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: Sun, 03 Aug 2008 21:53:47 -0000 http://perforce.freebsd.org/chv.cgi?CH=146568 Change 146568 by andenore@andenore_laptop on 2008/08/03 21:53:20 Improved progress indication for pkg_add -r, added date comparison for pkg_info, running e.g., pkg_info -M '*>2008 07 18' will list all installed packages after YYYY MM DD. Also added the caching of date to dbcache, so the lookup is done fast. Affected files ... .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#9 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/Makefile#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/Makefile#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#9 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/info.h#5 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#9 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#8 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#7 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#9 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/date.c#1 add .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/file.c#3 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/global.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#12 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/match.c#7 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/url.c#4 edit .. //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/version/Makefile#5 edit Differences ... ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/CHANGES#9 (text+ko) ==== @@ -13,7 +13,7 @@ significantly. - Uses human readable output for -s (size option) I'm not sure if this breaks things, but it looks Ok. (The old output is available via the -b option) - - Check installation date with -n (human readable) or -N (seconds since epoch) + - Print installation date with -n (human readable) or -N (seconds since epoch) Add: - Indexes information to dbcache according to the add ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/add/Makefile#4 (text+ko) ==== @@ -11,7 +11,4 @@ DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} LDADD= ${LIBINSTALL} -lfetch -lmd -test: - ./test.sh - .include ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/Makefile#4 (text+ko) ==== @@ -2,7 +2,7 @@ PROG= pkg_convert SRCS= perform.c main.c -CFLAGS+= -I${.CURDIR}/../lib -g +CFLAGS+= -I${.CURDIR}/../lib WARNS?= 3 #WFORMAT?= 1 ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/convert/perform.c#9 (text+ko) ==== ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/info.h#5 (text+ko) ==== @@ -67,6 +67,7 @@ extern Boolean UseBlkSz; extern Boolean KeepPackage; extern Boolean TimeEpoch; +extern Boolean DateMatch; extern char *InfoPrefix; extern char PlayPen[]; extern char *CheckPkg; ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/main.c#9 (text+ko) ==== @@ -33,6 +33,7 @@ Boolean QUIET = FALSE; Boolean UseBlkSz = FALSE; Boolean TimeEpoch = FALSE; +Boolean DateMatch = FALSE; char *InfoPrefix = (char *)(uintptr_t)""; char PlayPen[FILENAME_MAX]; char *CheckPkg = NULL; @@ -42,7 +43,7 @@ static void usage(void); -static char opts[] = "abcdDe:EfgGhiIjkKl:LmnNoO:pPqQrRst:TvVW:xX"; +static char opts[] = "abcdDe:EfgGhiIjkKl:LmMnNoO:pPqQrRst:TvVW:xX"; static struct option longopts[] = { { "all", no_argument, NULL, 'a' }, { "blocksize", no_argument, NULL, 'b' }, @@ -92,11 +93,15 @@ case 'a': MatchType = MATCH_ALL; break; + case 'b': + UseBlkSz = TRUE; + break; case 'v': Verbose++; /* Reasonable definition of 'everything' */ Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | - SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE; + SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE | + SHOW_DATE; break; case 'E': @@ -167,6 +172,10 @@ Flags |= SHOW_MTREE; break; + case 'M': + DateMatch = TRUE; + break; + case 's': Flags |= SHOW_SIZE; break; @@ -256,37 +265,36 @@ printf("Package tools revision: "); printf("%d\n", PKG_INSTALL_VERSION); exit(0); - } /* Set some reasonable defaults */ - if (!Flags) - Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; + if (!Flags) + Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; /* Get all the remaining package names, if any */ - while (*argv) { - /* - * Don't try to apply heuristics if arguments are regexs or if - * the argument refers to an existing file. + while (*argv) { + /* + * Don't try to apply heuristics if arguments are regexs or if + * the argument refers to an existing file. + */ + if (MatchType != MATCH_REGEX && MatchType != MATCH_EREGEX && !isfile(*argv) && !isURL(*argv)) { + while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { + *pkgs_split++ = '\0'; + /* + * If character after the '/' is alphanumeric or shell + * metachar, then we've found the package name. Otherwise + * we've come across a trailing '/' and need to continue our + * quest. */ - if (MatchType != MATCH_REGEX && MatchType != MATCH_EREGEX && !isfile(*argv) && !isURL(*argv)) { - while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { - *pkgs_split++ = '\0'; - /* - * If character after the '/' is alphanumeric or shell - * metachar, then we've found the package name. Otherwise - * we've come across a trailing '/' and need to continue our - * quest. - */ - if (isalnum(*pkgs_split) || ((MatchType == MATCH_GLOB) && \ - strpbrk(pkgs_split, "*?[]") != NULL)) { - *argv = pkgs_split; - break; - } - } + if (isalnum(*pkgs_split) || ((MatchType == MATCH_GLOB) && \ + strpbrk(pkgs_split, "*?[]") != NULL)) { + *argv = pkgs_split; + break; } - *pkgs++ = *argv++; + } } + *pkgs++ = *argv++; + } /* If no packages, yelp */ if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg && ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/perform.c#8 (text+ko) ==== @@ -43,47 +43,47 @@ signal(SIGINT, cleanup); /* Overriding action? */ - if (Flags & SHOW_PKGNAME) { - return matched_packages(pkgs); - } else if (CheckPkg) { - return isinstalledpkg(CheckPkg) > 0 ? 0 : 1; + if (Flags & SHOW_PKGNAME) { + return matched_packages(pkgs); + } else if (CheckPkg) { + return isinstalledpkg(CheckPkg) > 0 ? 0 : 1; /* Not reached */ - } else if (!TAILQ_EMPTY(whead)) { - return find_pkg(whead); - } else if (LookUpOrigin != NULL) { - return find_pkgs_by_origin(LookUpOrigin); - } + } else if (!TAILQ_EMPTY(whead)) { + return find_pkg(whead); + } else if (LookUpOrigin != NULL) { + return find_pkgs_by_origin(LookUpOrigin); + } - if (MatchType != MATCH_EXACT) { - matched = matchinstalled(MatchType, pkgs, &errcode); + if (MatchType != MATCH_EXACT) { + matched = matchinstalled(MatchType * (DateMatch ? 10 : 1), pkgs, &errcode); - if (errcode != 0) - return 1; - /* Not reached */ + if (errcode != 0) + return 1; + /* Not reached */ - if (matched != NULL) - pkgs = matched; - else switch (MatchType) { - case MATCH_GLOB: - break; - case MATCH_ALL: - warnx("no packages installed"); - return 0; - /* Not reached */ - case MATCH_REGEX: - case MATCH_EREGEX: - warnx("no packages match pattern(s)"); - return 1; - /* Not reached */ - default: - break; - } + if (matched != NULL) + pkgs = matched; + else switch (MatchType) { + case MATCH_GLOB: + break; + case MATCH_ALL: + warnx("no packages installed"); + return 0; + /* Not reached */ + case MATCH_REGEX: + case MATCH_EREGEX: + warnx("no packages match pattern(s)"); + return 1; + /* Not reached */ + default: + break; } + } - for (i = 0; pkgs[i]; i++) - err_cnt += pkg_do(pkgs[i]); + for (i = 0; pkgs[i]; i++) + err_cnt += pkg_do(pkgs[i]); - return err_cnt; + return err_cnt; } static char *Home; @@ -101,89 +101,89 @@ int code = 0; if (isURL(pkg)) { - if ((cp = fileGetURL(NULL, pkg, KeepPackage)) != NULL) { - if (!getcwd(fname, FILENAME_MAX)) - upchuck("getcwd"); - isTMP = TRUE; - } else { - goto bail; - } + if ((cp = fileGetURL(NULL, pkg, KeepPackage)) != NULL) { + if (!getcwd(fname, FILENAME_MAX)) + upchuck("getcwd"); + isTMP = TRUE; + } else { + goto bail; + } } else if (fexists(pkg) && isfile(pkg)) { - int len; + int len; - if (*pkg != '/') { - if (!getcwd(fname, FILENAME_MAX)) - upchuck("getcwd"); - len = strlen(fname); - snprintf(&fname[len], FILENAME_MAX - len, "/%s", pkg); - } - else - strcpy(fname, pkg); - cp = fname; - } else { - if ((cp = fileFindByPath(NULL, pkg)) != NULL) - strncpy(fname, cp, FILENAME_MAX); + if (*pkg != '/') { + if (!getcwd(fname, FILENAME_MAX)) + upchuck("getcwd"); + len = strlen(fname); + snprintf(&fname[len], FILENAME_MAX - len, "/%s", pkg); } + else + strcpy(fname, pkg); + cp = fname; + } else { + if ((cp = fileFindByPath(NULL, pkg)) != NULL) + strncpy(fname, cp, FILENAME_MAX); + } - if (cp) { - if (!isURL(pkg)) { - /* - * Apply a crude heuristic to see how much space the package will - * take up once it's unpacked. I've noticed that most packages - * compress an average of 75%, but we're only unpacking the + files so - * be very optimistic. - */ - if (stat(fname, &sb) == FAIL) { - warnx("can't stat package file '%s'", fname); - code = 1; - goto bail; - } - Home = make_playpen(PlayPen, sb.st_size / 2); - if (unpack(fname, "'+*'")) { - warnx("error during unpacking, no info for '%s' available", pkg); - code = 1; - goto bail; - } - } + if (cp) { + if (!isURL(pkg)) { + /* + * Apply a crude heuristic to see how much space the package will + * take up once it's unpacked. I've noticed that most packages + * compress an average of 75%, but we're only unpacking the + files so + * be very optimistic. + */ + if (stat(fname, &sb) == FAIL) { + warnx("can't stat package file '%s'", fname); + code = 1; + goto bail; + } + Home = make_playpen(PlayPen, sb.st_size / 2); + if (unpack(fname, "'+*'")) { + warnx("error during unpacking, no info for '%s' available", pkg); + code = 1; + goto bail; + } } + } /* It's not an uninstalled package, try and find it among the installed */ - else { - int isinstalled = isinstalledpkg(pkg); - if (isinstalled < 0) { - warnx("the package info for package '%s' is corrupt", pkg); - return 1; - } else if (isinstalled == 0) { - warnx("can't find package '%s' installed or in a file!", pkg); - return 1; - } - sprintf(log_dir, "%s/%s", LOG_DIR, pkg); - if (chdir(log_dir) == FAIL) { - warnx("can't change directory to '%s'!", log_dir); - return 1; - } - installed = TRUE; + else { + int isinstalled = isinstalledpkg(pkg); + if (isinstalled < 0) { + warnx("the package info for package '%s' is corrupt", pkg); + return 1; + } else if (isinstalled == 0) { + warnx("can't find package '%s' installed or in a file!", pkg); + return 1; + } + sprintf(log_dir, "%s/%s", LOG_DIR, pkg); + if (chdir(log_dir) == FAIL) { + warnx("can't change directory to '%s'!", log_dir); + return 1; } + installed = TRUE; + } - plist.head = plist.tail = NULL; + plist.head = plist.tail = NULL; - /* We don't want to read the packinglist if not necessary (it's slow) */ - if (Flags & SHOW_DEPEND || Flags & SHOW_PLIST || Flags & SHOW_PREFIX || - Flags & SHOW_FILES || Flags & SHOW_SIZE || Flags & SHOW_CKSUM || - Flags & SHOW_ORIGIN || Flags & SHOW_FMTREV || Flags & SHOW_DATE) { + /* We don't want to read the packinglist if not necessary (it's slow) */ + if (Flags & SHOW_DEPEND || Flags & SHOW_PLIST || Flags & SHOW_PREFIX || + Flags & SHOW_FILES || Flags & SHOW_SIZE || Flags & SHOW_CKSUM || + Flags & SHOW_ORIGIN || Flags & SHOW_FMTREV || Flags & SHOW_DATE) { - /* Suck in the contents list */ - fp = fopen(CONTENTS_FNAME, "r"); - if (!fp) { - warnx("unable to open %s file", CONTENTS_FNAME); - code = 1; - goto bail; - } - /* If we have a prefix, add it now */ - read_plist(&plist, fp); - fclose(fp); + /* Suck in the contents list */ + fp = fopen(CONTENTS_FNAME, "r"); + if (!fp) { + warnx("unable to open %s file", CONTENTS_FNAME); + code = 1; + goto bail; } + /* If we have a prefix, add it now */ + read_plist(&plist, fp); + fclose(fp); + } - /* + /* * Index is special info type that has to override all others to make * any sense (this is the default behaviour of pkg_info). */ @@ -241,7 +241,7 @@ } if(plist.head != NULL && plist.tail != NULL) - free_plist(&plist); + free_plist(&plist); bail: leave_playpen(); @@ -345,115 +345,115 @@ static int find_pkg(struct which_head *which_list) { - char **installed; - int errcode, i; - struct which_entry *wp; + char **installed; + int errcode, i; + struct which_entry *wp; - /* Converts files in which_list to the absolute path of the file */ - TAILQ_FOREACH(wp, which_list, next) { - const char *msg = "file cannot be found"; - char *tmp; + /* Converts files in which_list to the absolute path of the file */ + TAILQ_FOREACH(wp, which_list, next) { + const char *msg = "file cannot be found"; + char *tmp; - wp->skip = TRUE; - /* If it's not a file, we'll see if it's an executable. */ - if (isfile(wp->file) == FALSE) { - if (strchr(wp->file, '/') == NULL) { - tmp = vpipe("/usr/bin/which %s", wp->file); - if (tmp != NULL) { - strlcpy(wp->file, tmp, PATH_MAX); - wp->skip = FALSE; - free(tmp); - } else - msg = "file is not in PATH"; - } - } else { - tmp = abspath(wp->file); - if (isfile(tmp)) { - strlcpy(wp->file, tmp, PATH_MAX); - wp->skip = FALSE; - } - free(tmp); - } - if (wp->skip == TRUE) - warnx("%s: %s", wp->file, msg); + wp->skip = TRUE; + /* If it's not a file, we'll see if it's an executable. */ + if (isfile(wp->file) == FALSE) { + if (strchr(wp->file, '/') == NULL) { + tmp = vpipe("/usr/bin/which %s", wp->file); + if (tmp != NULL) { + strlcpy(wp->file, tmp, PATH_MAX); + wp->skip = FALSE; + free(tmp); + } else + msg = "file is not in PATH"; + } + } else { + tmp = abspath(wp->file); + if (isfile(tmp)) { + strlcpy(wp->file, tmp, PATH_MAX); + wp->skip = FALSE; + } + free(tmp); } + if (wp->skip == TRUE) + warnx("%s: %s", wp->file, msg); + } - /* If cache exists check database for the key (i.e., file absolute path) */ - if (CacheExists == TRUE) { + /* If cache exists check database for the key (i.e., file absolute path) */ + if (CacheExists == TRUE) { // DEBUG("find_pkg: USES CACHE\n"); - TAILQ_FOREACH(wp, which_list, next) { - if (wp->skip == TRUE) - continue; - DBT tmp; - if (dbKeyExists(wp->file, &tmp)) - strlcpy(wp->package, tmp.data, PATH_MAX); - else - DEBUG("find_pkg: Doesn't exist\n"); - } - } else { - DEBUG("debug: not using cache; run pkg_convert\n"); + TAILQ_FOREACH(wp, which_list, next) { + if (wp->skip == TRUE) + continue; + DBT tmp; + if (dbKeyExists(wp->file, &tmp)) + strlcpy(wp->package, tmp.data, PATH_MAX); + else + DEBUG("find_pkg: Doesn't exist\n"); + } + } else { + DEBUG("debug: not using cache; run pkg_convert\n"); installed = matchinstalled(MATCH_ALL, NULL, &errcode); if (installed == NULL) - return errcode; + return errcode; for (i = 0; installed[i] != NULL; i++) { - FILE *fp; - Package pkg; - PackingList itr; - char *cwd = NULL; - char tmp[PATH_MAX]; + FILE *fp; + Package pkg; + PackingList itr; + char *cwd = NULL; + char tmp[PATH_MAX]; - snprintf(tmp, PATH_MAX, "%s/%s/%s", LOG_DIR, installed[i], - CONTENTS_FNAME); - fp = fopen(tmp, "r"); - if (fp == NULL) { - warn("%s", tmp); - return 1; - } + snprintf(tmp, PATH_MAX, "%s/%s/%s", LOG_DIR, installed[i], + CONTENTS_FNAME); + fp = fopen(tmp, "r"); + if (fp == NULL) { + warn("%s", tmp); + return 1; + } - pkg.head = pkg.tail = NULL; - read_plist(&pkg, fp); - fclose(fp); - for (itr = pkg.head; itr != pkg.tail; itr = itr->next) { - if (itr->type == PLIST_CWD) { - cwd = itr->name; - } else if (itr->type == PLIST_FILE) { - TAILQ_FOREACH(wp, which_list, next) { - if (wp->skip == TRUE) - continue; - if (!cmp_path(wp->file, itr->name, cwd)) - continue; - if (wp->package[0] != '\0') { - warnx("both %s and %s claim to have installed %s\n", - wp->package, installed[i], wp->file); - } else { - strlcpy(wp->package, installed[i], PATH_MAX); - } - } + pkg.head = pkg.tail = NULL; + read_plist(&pkg, fp); + fclose(fp); + for (itr = pkg.head; itr != pkg.tail; itr = itr->next) { + if (itr->type == PLIST_CWD) { + cwd = itr->name; + } else if (itr->type == PLIST_FILE) { + TAILQ_FOREACH(wp, which_list, next) { + if (wp->skip == TRUE) + continue; + if (!cmp_path(wp->file, itr->name, cwd)) + continue; + if (wp->package[0] != '\0') { + warnx("both %s and %s claim to have installed %s\n", + wp->package, installed[i], wp->file); + } else { + strlcpy(wp->package, installed[i], PATH_MAX); } + } } - free_plist(&pkg); + } + free_plist(&pkg); } - } + } - TAILQ_FOREACH(wp, which_list, next) { - if (wp->package[0] != '\0') { - if (Quiet) - puts(wp->package); - else - printf("%s was installed by package %s\n", \ - wp->file, wp->package); - } + TAILQ_FOREACH(wp, which_list, next) { + if (wp->package[0] != '\0') { + if (Quiet) + puts(wp->package); + else + printf("%s was installed by package %s\n", \ + wp->file, wp->package); } - while (!TAILQ_EMPTY(which_list)) { - wp = TAILQ_FIRST(which_list); - TAILQ_REMOVE(which_list, wp, next); - free(wp); - } + } + while (!TAILQ_EMPTY(which_list)) { + wp = TAILQ_FIRST(which_list); + TAILQ_REMOVE(which_list, wp, next); + free(wp); + } - free(which_list); - return 0; + free(which_list); + return 0; } /* @@ -466,21 +466,21 @@ static int find_pkgs_by_origin(const char *origin) { - char **matched; - int errcode, i; + char **matched; + int errcode, i; - if (!Quiet) - printf("The following installed package(s) has %s origin:\n", origin); + if (!Quiet) + printf("The following installed package(s) has %s origin:\n", origin); - matched = matchbyorigin(origin, &errcode); - if (matched == NULL) - return errcode; + matched = matchbyorigin(origin, &errcode); + if (matched == NULL) + return errcode; - for (i = 0; matched[i] != NULL; i++) { - puts(matched[i]); - } + for (i = 0; matched[i] != NULL; i++) { + puts(matched[i]); + } - return 0; + return 0; } /* ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/info/show.c#7 (text+ko) ==== @@ -29,19 +29,6 @@ #include #include -char sizeTable[][4] = { "B", "kB", "MB", "GB", "TB" }; - -unsigned int -human_readable(unsigned int size, int *index) -{ - if (size >= 1024) { - *index = *index + 1; - return human_readable(size/1024, index); - } - - return size; -} - void show_file(const char *title, const char *fname) { @@ -267,70 +254,68 @@ void show_size(const char *title, Package *plist) { - PackingList p; - Boolean ign = FALSE; - const char *dir = "."; - struct stat sb; - char tmp[FILENAME_MAX]; - unsigned long size = 0; - long blksize; - int headerlen; - char *descr; - char *prefix = NULL; + PackingList p; + Boolean ign = FALSE; + const char *dir = "."; + struct stat sb; + char tmp[FILENAME_MAX]; + unsigned long size = 0; + long blksize; + int headerlen; + char *descr; + char *prefix = NULL; - descr = getbsize(&headerlen, &blksize); - if (!Quiet) - printf("%s%s", InfoPrefix, title); + descr = getbsize(&headerlen, &blksize); + if (!Quiet) + printf("%s%s", InfoPrefix, title); - for (p = plist->head; p != NULL; p = p->next) { - switch (p->type) { + for (p = plist->head; p != NULL; p = p->next) { + switch (p->type) { case PLIST_FILE: - if (!ign) { - snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name); - if (!lstat(tmp, &sb)) { - size += sb.st_size; + if (!ign) { + snprintf(tmp, FILENAME_MAX, "%s/%s", dir, p->name); + if (!lstat(tmp, &sb)) { + size += sb.st_size; - if (Verbose) - printf("%lu\t%s\n", - (unsigned long) howmany(sb.st_size, blksize), tmp); - } + if (Verbose) + printf("%lu\t%s\n", + (unsigned long) howmany(sb.st_size, blksize), tmp); } - ign = FALSE; - break; + } + ign = FALSE; + break; case PLIST_CWD: - if (!prefix) - prefix = p->name; + if (!prefix) + prefix = p->name; - if (p->name == NULL) - dir = prefix; - else - dir = p->name; - break; + if (p->name == NULL) + dir = prefix; + else + dir = p->name; + break; case PLIST_IGNORE: - ign = TRUE; - break; + ign = TRUE; + break; /* Silence GCC in the -Wall mode */ default: - break; + break; } + } + + if (!Quiet) { + if (UseBlkSz) + printf("%lu\t(%s)\n", howmany(size, blksize), descr); + else { + printf("%s\n", printHumanReadable(size)); } - - if (!Quiet) { - if (UseBlkSz) - printf("%lu\t(%s)\n", howmany(size, blksize), descr); - else { - int index = 0; - printf("%lu ", human_readable(size, &index)); - printf("%s\n", &sizeTable[index]); - } - } else - if (UseBlkSz) - printf("%lu\n", howmany(size, blksize)); - else - printf("%lu\n", size); + } else + if (UseBlkSz) + printf("%lu\n", howmany(size, blksize)); + else + printf("%lu\n", size); } /* Show files that don't match the recorded checksum */ ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/Makefile#4 (text+ko) ==== @@ -3,7 +3,7 @@ LIB= install INTERNALLIB= 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 + deps.c version.c pkgwrap.c url.c date.c CFLAGS= WARNS?= 3 ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/database.c#9 (text+ko) ==== @@ -229,9 +229,11 @@ Boolean skip = FALSE; char *cwd; DBT key, data; + time_t etime; + struct stat fstat; if (pkg->name == NULL || pkg->origin == NULL) { - if(showmsg) + if (showmsg) warnx("%s does not appear to be a valid package!", pkg->name); return 1; } @@ -241,7 +243,7 @@ data.size = strlen(pkg->origin) + 1; data.data = (char *)pkg->origin; - if(showmsg) + if (showmsg) printf("Saving package: %s\n", (char *)key.data); dbsave(&key, &data); @@ -274,5 +276,30 @@ } skip = FALSE; } + + /* Cache installtime */ + if (pkg->datetime != 0) + etime = pkg->datetime; + else { + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/%s/%s", LOG_DIR, pkg->name, CONTENTS_FNAME); + if (stat(path, &fstat) == -1) + warn("Cannot stat file: %s", path); + etime = fstat.st_mtime; + } + + char *tmp[128], tmp2[128]; + snprintf(&tmp, sizeof(tmp), "+D%s", pkg->name); + snprintf(&tmp2, sizeof(tmp2), "%d", (int)etime); + + key.size = strlen(tmp) + 1; + key.data = (char *)tmp; + data.size = strlen(tmp2) + 1; + data.data = (char *)tmp2; + dbsave(&key, &data); + + if (Verbose && showmsg) + printf("Saving installdate: %s %s\n", tmp, tmp2); + return 0; } ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/file.c#3 (text+ko) ==== @@ -27,6 +27,8 @@ #include #include +char sizeTable[][5] = { "Byte", "kB", "MB", "GB", "TB" }; + /* Quick check to see if a file exists */ Boolean fexists(const char *fname) @@ -425,3 +427,63 @@ } *buf = '\0'; } + +int +power(int base, int n) +{ + int i; + + for (i = 1; i= 1024) { + if (precision) + *precision = (size % 1024); + + *index = *index + 1; + return human_readable(size/1024, precision, num, index); + } + + if (precision) { + if (num <= 0) + num = 1; + + *precision = (*precision * power(10, num)); + *precision /= 1024; + } + + return size; +} + +char * +printHumanReadable(unsigned int size) +{ + static char result[32]; + int index = 0; + int tmpSize = 0, precision = 0; + + tmpSize = human_readable(size, &precision, 1, &index); + snprintf(result, PATH_MAX, "%d.%01d ", tmpSize, precision); + + if (index > sizeof(sizeTable)) + warnx("printHumanReadable: sizeTable out of bounds"); + else + strcat(result, sizeTable[index]); + + return result; +} + ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/global.c#4 (text+ko) ==== @@ -31,4 +31,5 @@ int AutoAnswer = FALSE; int Verbose = 0; /* Allow multiple levels of verbose. */ DB *database = NULL; -Boolean CacheExists = FALSE; /* TRUE if cache exists (bdb file) */+Boolean CacheExists = FALSE; /* TRUE if cache exists (bdb file) */ + ==== //depot/projects/soc2008/andenore_pkginstall/src/usr.sbin/pkg_install/lib/lib.h#12 (text+ko) ==== @@ -135,7 +135,7 @@ typedef enum _plist_t plist_t; enum _match_t { - MATCH_ALL, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX + MATCH_ALL = 1, MATCH_EXACT, MATCH_GLOB, MATCH_NGLOB, MATCH_EREGEX, MATCH_REGEX }; typedef enum _match_t match_t; @@ -164,6 +164,7 @@ }; STAILQ_HEAD(reqr_by_head, reqr_by_entry); + /* Prototypes */ /* Misc */ int vsystem(const char *, ...); @@ -206,6 +207,7 @@ int unpack(const char *, const char *); void format_cmd(char *, int, const char *, const char *, const char *); + /* Msg */ >>> TRUNCATED FOR MAIL (1000 lines) <<<