[darwinbuild-changes] [682] branches/PR-7341154/darwinup

source_changes at macosforge.org source_changes at macosforge.org
Sat Jan 30 13:38:27 PST 2010


Revision: 682
          http://trac.macosforge.org/projects/darwinbuild/changeset/682
Author:   wsiegrist at apple.com
Date:     2010-01-30 13:38:23 -0800 (Sat, 30 Jan 2010)
Log Message:
-----------
Add upgrade command

Modified Paths:
--------------
    branches/PR-7341154/darwinup/Depot.cpp
    branches/PR-7341154/darwinup/Depot.h
    branches/PR-7341154/darwinup/main.cpp

Modified: branches/PR-7341154/darwinup/Depot.cpp
===================================================================
--- branches/PR-7341154/darwinup/Depot.cpp	2010-01-30 21:25:24 UTC (rev 681)
+++ branches/PR-7341154/darwinup/Depot.cpp	2010-01-30 21:38:23 UTC (rev 682)
@@ -683,6 +683,34 @@
 }
 
 
+int Depot::install(const char* path) {
+	int res = 0;
+	char uuid[37];
+	Archive* archive = ArchiveFactory(path, this->downloads_path());
+	if (archive) {
+		res = this->install(archive);
+		if (res == 0) {
+			uuid_unparse_upper(archive->uuid(), uuid);
+			fprintf(stdout, "%s\n", uuid);
+		} else {
+			fprintf(stderr, "Error: Install failed. Rolling back installation.\n");
+			res = this->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 {
+		fprintf(stderr, "Archive not found: %s\n", path);
+	}
+
+	return res;
+}
+
+
 int Depot::install(Archive* archive) {
 	int res = 0;
 	Archive* rollback = new RollbackArchive();

Modified: branches/PR-7341154/darwinup/Depot.h
===================================================================
--- branches/PR-7341154/darwinup/Depot.h	2010-01-30 21:25:24 UTC (rev 681)
+++ branches/PR-7341154/darwinup/Depot.h	2010-01-30 21:38:23 UTC (rev 682)
@@ -82,6 +82,7 @@
 	int list();
 	static int list_archive(Archive* archive, void* context);
 
+	int install(const char* path);
 	int install(Archive* archive);
 	static int install_file(File* file, void* context);
 	static int backup_file(File* file, void* context);

Modified: branches/PR-7341154/darwinup/main.cpp
===================================================================
--- branches/PR-7341154/darwinup/main.cpp	2010-01-30 21:25:24 UTC (rev 681)
+++ branches/PR-7341154/darwinup/main.cpp	2010-01-30 21:38:23 UTC (rev 682)
@@ -50,10 +50,11 @@
 	fprintf(stderr, "          -v         verbose (use -vv for extra verbosity)     \n");
 	fprintf(stderr, "                                                               \n");
 	fprintf(stderr, "commands:                                                      \n");
+	fprintf(stderr, "          files      <archive>                                 \n");
 	fprintf(stderr, "          install    <path>                                    \n");
 	fprintf(stderr, "          list                                                 \n");
-	fprintf(stderr, "          files      <archive>                                 \n");
 	fprintf(stderr, "          uninstall  <archive>                                 \n");
+	fprintf(stderr, "          upgrade    <path>                                    \n");
 	fprintf(stderr, "          verify     <archive>                                 \n");
 	fprintf(stderr, "                                                               \n");
 	fprintf(stderr, "<path> is one of:                                              \n");
@@ -139,27 +140,18 @@
 	}
 	
 	if (argc == 2 && strcmp(argv[0], "install") == 0) {
-		char uuid[37];
-		Archive* archive = ArchiveFactory(argv[1], depot->downloads_path());
-		if (archive) {
-			res = depot->install(archive);
-			if (res == 0) {
-				uuid_unparse_upper(archive->uuid(), uuid);
-				fprintf(stdout, "%s\n", uuid);
-			} else {
-				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 {
-			fprintf(stderr, "Archive not found: %s\n", argv[1]);
+		res = depot->install(argv[1]);
+	} else if (argc == 2 && strcmp(argv[0], "upgrade") == 0) {
+		// find most recent matching archive by name
+		Archive* old = depot->get_archive(basename(argv[1]));
+		if (!old) {
+			fprintf(stderr, "Error: unable to find a matching root to upgrade.");
+			res = 5;
 		}
+		// install new archive
+		if (res == 0) res = depot->install(argv[1]);
+		// uninstall old archive
+		if (res == 0) res = depot->uninstall(old);
 	} else if (argc == 1 && strcmp(argv[0], "list") == 0) {
 		depot->list();
 	} else if (argc == 1 && strcmp(argv[0], "dump") == 0) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100130/f78ed75d/attachment.html>


More information about the darwinbuild-changes mailing list