From owner-p4-projects@FreeBSD.ORG Wed Jul 28 08:21:36 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7880A1065C66; Wed, 28 Jul 2010 08:21:36 +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 1BAA41065BF5 for ; Wed, 28 Jul 2010 08:21:35 +0000 (UTC) (envelope-from jlaffaye@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id A463A8FC19 for ; Wed, 28 Jul 2010 08:21:35 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.4/8.14.4) with ESMTP id o6S8LZmj009137 for ; Wed, 28 Jul 2010 08:21:35 GMT (envelope-from jlaffaye@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.4/8.14.4/Submit) id o6S8LZSI009135 for perforce@freebsd.org; Wed, 28 Jul 2010 08:21:35 GMT (envelope-from jlaffaye@FreeBSD.org) Date: Wed, 28 Jul 2010 08:21:35 GMT Message-Id: <201007280821.o6S8LZSI009135@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jlaffaye@FreeBSD.org using -f From: Julien Laffaye To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 181464 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jul 2010 08:21:36 -0000 http://p4web.freebsd.org/@@181464?ac=10 Change 181464 by jlaffaye@jlaffaye-chulak on 2010/07/25 20:32:27 Cleanup the directory in LOG_DIR when a signal is received. Remove the temporary directory when it is a fake install or if the user doesn't want to register the package. Affected files ... .. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#7 edit .. //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/perform.c#7 edit Differences ... ==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/extract.c#7 (text+ko) ==== @@ -31,6 +31,11 @@ #include "add.h" +/* Globals used by cleanup() */ +int extract_state; +char db_dir_tmp[FILENAME_MAX]; +char db_dir[FILENAME_MAX]; + int extract_plist(struct archive *a, struct archive_entry *entry, Package *pkg) { char *plist_buf; @@ -71,8 +76,6 @@ int code = 0; int errcode = 0; char cmd[FILENAME_MAX]; - char db_dir_tmp[FILENAME_MAX]; - char db_dir[FILENAME_MAX]; char pre_script[FILENAME_MAX] = INSTALL_FNAME; char post_script[FILENAME_MAX]; char pre_arg[FILENAME_MAX]; @@ -83,6 +86,9 @@ int fd; struct stat sb; + /* Nothing to cleanup yet */ + extract_state = 0; + /* * If we have a prefix, delete the first one we see and add this * one in place of it. @@ -304,6 +310,8 @@ warnx("Can not create '%s' directory - aborting", db_dir_tmp); return (1); } + /* Tell cleanup that we have a temporary dir in LOG_DIR */ + extract_state = 1; if (chdir(db_dir_tmp) == -1) { warn("chdir(%s) - aborting", db_dir_tmp); vsystem("%s -rf %s", REMOVE_CMD, db_dir_tmp); @@ -601,9 +609,17 @@ /* Atomically register the package */ if (rename(db_dir_tmp, db_dir) == -1) warn("Can not rename '%s' to '%s'", db_dir_tmp, db_dir); - else if (Verbose) - printf("Package %s registered in %s\n", pkg->name, db_dir); - } + else { + extract_state = 2; + if (Verbose) + printf("Package %s registered in %s\n", pkg->name, db_dir); + } + } else /* !NoRecord && !Fake */ + /* + * It was a fake or the user doesn't want to register the package, + * so we remove our temporary directory + */ + vsystem("%s -rf %s", REMOVE_CMD, db_dir_tmp); if ((p = find_plist(pkg, PLIST_DISPLAY)) != NULL) { FILE *fp; ==== //depot/projects/soc2010/pkg_complete/usr.sbin/pkg_install/add/perform.c#7 (text+ko) ==== @@ -35,6 +35,10 @@ void cleanup(void); static int pkg_do(char *); +extern int extract_state; +extern char db_dir_tmp[FILENAME_MAX]; +extern char db_dir[FILENAME_MAX]; + int pkg_perform(char **pkgs) { @@ -216,5 +220,8 @@ void cleanup(void) { - /* TODO */ + if (extract_state == 1) + vsystem("%s -rf %s", REMOVE_CMD, db_dir_tmp); + else if (extract_state == 2) + vsystem("%s -rf %s", REMOVE_CMD, db_dir); }