Revision
637
Author
wsiegrist@apple.com
Date
2009-11-11 15:44:51 -0800 (Wed, 11 Nov 2009)

Log Message

Ensure -p option is an absolute path. Ignore EEXIST when making directories during install since we use copyfile() instead of rename() now. Uninstall root when install fails so we leave the system in a consistent state.

Modified Paths

Diff

Modified: branches/PR-7250612/darwinup/File.cpp (636 => 637)


--- branches/PR-7250612/darwinup/File.cpp	2009-11-11 23:43:07 UTC (rev 636)
+++ branches/PR-7250612/darwinup/File.cpp	2009-11-11 23:44:51 UTC (rev 637)
@@ -296,6 +296,7 @@
 	
 	IF_DEBUG("[install] mkdir(%s, %04o)\n", dstpath, mode);
 	if (res == 0) res = mkdir(dstpath, mode);
+	if (res && errno == EEXIST) res = 0;
 	if (res != 0) fprintf(stderr, "ERROR: %s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);
 	if (res == 0) res = chown(dstpath, uid, gid);
 	if (res != 0) fprintf(stderr, "ERROR: %s:%d: %s: %s (%d)\n", __FILE__, __LINE__, dstpath, strerror(errno), errno);

Modified: branches/PR-7250612/darwinup/main.cpp (636 => 637)


--- branches/PR-7250612/darwinup/main.cpp	2009-11-11 23:43:07 UTC (rev 636)
+++ branches/PR-7250612/darwinup/main.cpp	2009-11-11 23:44:51 UTC (rev 637)
@@ -64,10 +64,14 @@
 			verbosity |= VERBOSE;
 			break;
 		case 'p':
-		        if (strlen(optarg) > (PATH_MAX - 1)) {
-			        fprintf(stderr, "Error: -p option value is too long \n");
-				exit(3);
-			}
+				if (optarg[0] != '/') {
+					fprintf(stderr, "Error: -p option must be an absolute path\n");
+					exit(4);
+				}
+				if (strlen(optarg) > (PATH_MAX - 1)) {
+					fprintf(stderr, "Error: -p option value is too long \n");
+					exit(4);
+				}
 			join_path(&path, optarg, "/");
 			break;
 		case '?':
@@ -101,7 +105,14 @@
 				uuid_unparse_upper(archive->uuid(), uuid);
 				fprintf(stdout, "%s\n", uuid);
 			} else {
-				fprintf(stderr, "An error occurred.\n");
+				fprintf(stderr, "Error: Install failed. Rolling back installation.\n");
+				res = depot->uninstall(archive);
+				if (res) {
+					fprintf(stderr, "Error: Unable to rollback installation. "
+							"Your system is in an inconsistent state! File a bug!\n");
+				} else {
+					fprintf(stderr, "Rollback successful.\n");
+				}
 				res = 1;
 			}
 		} else {