PERFORCE change 181464 for review
Julien Laffaye
jlaffaye at FreeBSD.org
Wed Jul 28 08:21:36 UTC 2010
http://p4web.freebsd.org/@@181464?ac=10
Change 181464 by jlaffaye at 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);
}
More information about the p4-projects
mailing list