[darwinbuild-changes] [661] branches/PR-7431723/darwinup

source_changes at macosforge.org source_changes at macosforge.org
Mon Dec 14 10:29:50 PST 2009


Revision: 661
          http://trac.macosforge.org/projects/darwinbuild/changeset/661
Author:   wsiegrist at apple.com
Date:     2009-12-14 10:29:47 -0800 (Mon, 14 Dec 2009)
Log Message:
-----------
Add archive lookup by serial and oldest/newest keywords

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

Modified: branches/PR-7431723/darwinup/Depot.cpp
===================================================================
--- branches/PR-7431723/darwinup/Depot.cpp	2009-12-14 18:03:59 UTC (rev 660)
+++ branches/PR-7431723/darwinup/Depot.cpp	2009-12-14 18:29:47 UTC (rev 661)
@@ -192,15 +192,62 @@
 	return archive;
 }
 
-Archive* Depot::archive(const char* uuid) {
-	uuid_t uu;
-	if (uuid_parse(uuid, uu) == 0) {
-		return Depot::archive(uu);
-	} else {
-		return NULL;
+Archive* Depot::archive(archive_keyword_t keyword) {
+	int res = 0;
+	Archive* archive = NULL;
+	static sqlite3_stmt* stmt = NULL;
+	const char* query = NULL;
+	if (stmt == NULL && m_db) {
+		if (keyword == DEPOT_ARCHIVE_NEWEST) {
+			query = "SELECT serial FROM archives WHERE name != '<Rollback>' ORDER BY date_added DESC LIMIT 1";
+		} else if (keyword == DEPOT_ARCHIVE_OLDEST) {
+			query = "SELECT serial FROM archives WHERE name != '<Rollback>' ORDER BY date_added ASC LIMIT 1";
+		} else {
+			fprintf(stderr, "Error: unknown archive keyword.\n");
+			res = -1;
+		}
+		if (res == 0) res = sqlite3_prepare(m_db, query, -1, &stmt, NULL);
+		if (res != 0) fprintf(stderr, "%s:%d: sqlite3_prepare: %s: %s (%d)\n", __FILE__, __LINE__, query, sqlite3_errmsg(m_db), res);
 	}
+	if (stmt && res == 0) {
+		res = sqlite3_step(stmt);
+		if (res == SQLITE_ROW) {
+			uint64_t serial = sqlite3_column_int64(stmt, 0);
+			archive = Depot::archive(serial);
+		}
+		sqlite3_reset(stmt);
+	}
+	return archive;	
 }
 
+// Return Archive from database matching arg, which is one of:
+//
+//   uuid (ex: 22969F32-9C4F-4370-82C8-DD3609736D8D)
+//   serial (ex: 12)
+//   keyword (either "newest" for the most recent root installed
+//            or     "oldest" for the oldest installed root)
+//   
+Archive* Depot::archive(const char* arg) {
+	uuid_t uuid;
+	uint64_t serial; 
+	if (uuid_parse(arg, uuid) == 0) {
+		return Depot::archive(uuid);
+	}
+	serial = strtoull(arg, NULL, 0);
+	if (serial) {
+		return Depot::archive(serial);
+	}
+	if (strncasecmp("oldest", arg, 6) == 0) {
+		IF_DEBUG("looking for oldest\n");
+		return Depot::archive(DEPOT_ARCHIVE_OLDEST);
+	}
+	if (strncasecmp("newest", arg, 6) == 0) {
+		IF_DEBUG("looking for newest\n");
+		return Depot::archive(DEPOT_ARCHIVE_NEWEST);
+	}
+	return NULL;
+}
+
 int Depot::iterate_archives(ArchiveIteratorFunc func, void* context) {
 	int res = 0;
 	static sqlite3_stmt* stmt = NULL;
@@ -812,6 +859,9 @@
 
 int Depot::list_archive(Archive* archive, void* context) {
 	extern uint32_t verbosity;
+	
+	uint64_t serial = archive->serial();
+	
 	char uuid[37];
 	uuid_unparse_upper(archive->uuid(), uuid);
 
@@ -823,7 +873,7 @@
 
 	if (!INFO_TEST(archive->info(), ARCHIVE_INFO_ROLLBACK) ||
 	    (verbosity & VERBOSE_DEBUG)) {
-		fprintf((FILE*)context, "%-36s  %-23s  %s\n", uuid, date, archive->name());
+		fprintf((FILE*)context, "%-6llu %-36s  %-23s  %s\n", serial, uuid, date, archive->name());
 	}
 	
 	return 0;
@@ -831,8 +881,8 @@
 
 int Depot::list() {
 	int res = 0;
-	fprintf(stdout, "%-36s  %-23s  %s\n", "UUID", "Date Installed", "Name");
-	fprintf(stdout, "====================================  =======================  =================\n");
+	fprintf(stdout, "%-6s %-36s  %-23s  %s\n", "Serial", "UUID", "Date Installed", "Name");
+	fprintf(stdout, "====== ====================================  =======================  =================\n");
 	if (res == 0) res = this->iterate_archives(&Depot::list_archive, stdout);
 	return res;
 }

Modified: branches/PR-7431723/darwinup/Depot.h
===================================================================
--- branches/PR-7431723/darwinup/Depot.h	2009-12-14 18:03:59 UTC (rev 660)
+++ branches/PR-7431723/darwinup/Depot.h	2009-12-14 18:29:47 UTC (rev 661)
@@ -40,6 +40,11 @@
 typedef int (*ArchiveIteratorFunc)(Archive* archive, void* context);
 typedef int (*FileIteratorFunc)(File* file, void* context);
 
+enum archive_keyword_t {
+		DEPOT_ARCHIVE_NEWEST,
+		DEPOT_ARCHIVE_OLDEST
+};
+
 struct Depot {
 	Depot();
 	Depot(const char* prefix);
@@ -59,7 +64,8 @@
 
 	Archive*	archive(uint64_t serial);
 	Archive*	archive(uuid_t uuid);
-	Archive*	archive(const char* uuid);
+	Archive*	archive(archive_keyword_t keyword);
+	Archive*	archive(const char* arg);
 
 	int dump();
 	static int dump_archive(Archive* archive, void* context);

Modified: branches/PR-7431723/darwinup/main.cpp
===================================================================
--- branches/PR-7431723/darwinup/main.cpp	2009-12-14 18:03:59 UTC (rev 660)
+++ branches/PR-7431723/darwinup/main.cpp	2009-12-14 18:29:47 UTC (rev 661)
@@ -52,9 +52,9 @@
 	fprintf(stderr, "commands:                                                      \n");
 	fprintf(stderr, "          install    <path>                                    \n");
 	fprintf(stderr, "          list                                                 \n");
-	fprintf(stderr, "          files      <uuid>                                    \n");
-	fprintf(stderr, "          uninstall  <uuid>                                    \n");
-	fprintf(stderr, "          verify     <uuid>                                    \n");
+	fprintf(stderr, "          files      <uuid>|<serial>|newest|oldest             \n");
+	fprintf(stderr, "          uninstall  <uuid>|<serial>|newest|oldest             \n");
+	fprintf(stderr, "          verify     <uuid>|<serial>|newest|oldest             \n");
 	exit(1);
 }
 
@@ -156,6 +156,11 @@
 	} else if (argc == 2 && strcmp(argv[0], "uninstall") == 0) {
 		Archive* archive = depot->archive(argv[1]);
 		if (archive) {
+			if (verbosity & VERBOSE_DEBUG) {
+				char uuid[37];
+				uuid_unparse_upper(archive->uuid(), uuid);
+				fprintf(stderr, "[uninstall] found archive: %s\n", uuid);
+			}
 			res = depot->uninstall(archive);
 			if (res != 0) {
 				fprintf(stderr, "An error occurred.\n");
@@ -169,6 +174,11 @@
 	} else if (argc == 2 && strcmp(argv[0], "verify") == 0) {
 		Archive* archive = depot->archive(argv[1]);
 		if (archive) {
+			if (verbosity & VERBOSE_DEBUG) {
+				char uuid[37];
+				uuid_unparse_upper(archive->uuid(), uuid);
+				fprintf(stderr, "[uninstall] found archive: %s\n", uuid);
+			}			
 			res = depot->verify(archive);
 			if (res != 0) {
 				fprintf(stderr, "An error occurred.\n");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20091214/5f741c27/attachment-0001.html>


More information about the darwinbuild-changes mailing list