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

source_changes at macosforge.org source_changes at macosforge.org
Mon Dec 14 11:13:58 PST 2009


Revision: 662
          http://trac.macosforge.org/projects/darwinbuild/changeset/662
Author:   wsiegrist at apple.com
Date:     2009-12-14 11:13:54 -0800 (Mon, 14 Dec 2009)
Log Message:
-----------
Add lookup by name, cleanup the usage statement.

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:29:47 UTC (rev 661)
+++ branches/PR-7431723/darwinup/Depot.cpp	2009-12-14 19:13:54 UTC (rev 662)
@@ -192,6 +192,40 @@
 	return archive;
 }
 
+// Unserialize an archive from the database.
+// Find the last archive installed with this name
+Archive* Depot::archive(archive_name_t name) {
+	int res = 0;
+	Archive* archive = NULL;
+	static sqlite3_stmt* stmt = NULL;
+	if (stmt == NULL && m_db) {
+		const char* query = "SELECT serial, uuid, info, date_added FROM archives WHERE name=? ORDER BY date_added DESC LIMIT 1";
+		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_bind_text(stmt, 1, name, -1, SQLITE_STATIC);
+		if (res == 0) res = sqlite3_step(stmt);
+		if (res == SQLITE_ROW) {
+			uuid_t uuid;
+			const void* blob = sqlite3_column_blob(stmt, 1);
+			int blobsize = sqlite3_column_bytes(stmt, 1);
+			if (blobsize > 0) {
+				assert(blobsize == sizeof(uuid_t));
+				memcpy(uuid, blob, sizeof(uuid_t));
+			} else {
+				uuid_clear(uuid);
+			}
+			uint64_t serial = sqlite3_column_int64(stmt, 0);
+			uint64_t info = sqlite3_column_int64(stmt, 2);
+			time_t date_added = sqlite3_column_int(stmt, 3);
+			archive = new Archive(serial, uuid, (const char*)name, NULL, info, date_added);
+		}
+		sqlite3_reset(stmt);
+	}
+	return archive;
+}
+
 Archive* Depot::archive(archive_keyword_t keyword) {
 	int res = 0;
 	Archive* archive = NULL;
@@ -224,6 +258,7 @@
 //
 //   uuid (ex: 22969F32-9C4F-4370-82C8-DD3609736D8D)
 //   serial (ex: 12)
+//   name  (ex root.tar.gz)
 //   keyword (either "newest" for the most recent root installed
 //            or     "oldest" for the oldest installed root)
 //   
@@ -245,7 +280,7 @@
 		IF_DEBUG("looking for newest\n");
 		return Depot::archive(DEPOT_ARCHIVE_NEWEST);
 	}
-	return NULL;
+	return Depot::archive((archive_name_t)arg);
 }
 
 int Depot::iterate_archives(ArchiveIteratorFunc func, void* context) {

Modified: branches/PR-7431723/darwinup/Depot.h
===================================================================
--- branches/PR-7431723/darwinup/Depot.h	2009-12-14 18:29:47 UTC (rev 661)
+++ branches/PR-7431723/darwinup/Depot.h	2009-12-14 19:13:54 UTC (rev 662)
@@ -40,6 +40,8 @@
 typedef int (*ArchiveIteratorFunc)(Archive* archive, void* context);
 typedef int (*FileIteratorFunc)(File* file, void* context);
 
+typedef char* archive_name_t;
+
 enum archive_keyword_t {
 		DEPOT_ARCHIVE_NEWEST,
 		DEPOT_ARCHIVE_OLDEST
@@ -64,6 +66,7 @@
 
 	Archive*	archive(uint64_t serial);
 	Archive*	archive(uuid_t uuid);
+	Archive*	archive(archive_name_t name);
 	Archive*	archive(archive_keyword_t keyword);
 	Archive*	archive(const char* arg);
 

Modified: branches/PR-7431723/darwinup/main.cpp
===================================================================
--- branches/PR-7431723/darwinup/main.cpp	2009-12-14 18:29:47 UTC (rev 661)
+++ branches/PR-7431723/darwinup/main.cpp	2009-12-14 19:13:54 UTC (rev 662)
@@ -52,9 +52,18 @@
 	fprintf(stderr, "commands:                                                      \n");
 	fprintf(stderr, "          install    <path>                                    \n");
 	fprintf(stderr, "          list                                                 \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");
+	fprintf(stderr, "          files      <archive>                                 \n");
+	fprintf(stderr, "          uninstall  <archive>                                 \n");
+	fprintf(stderr, "          verify     <archive>                                 \n");
+	fprintf(stderr, "                                                               \n");
+	fprintf(stderr, "<archive> is one of:                                           \n");
+	fprintf(stderr, "          <serial>   the Serial number                         \n");
+	fprintf(stderr, "          <uuid>     the UUID                                  \n");
+	fprintf(stderr, "          <name>     the last root installed with that name    \n");
+	fprintf(stderr, "          newest     the newest (last) root installed          \n");
+	fprintf(stderr, "          oldest     the oldest root installed                 \n");
+	fprintf(stderr, "          all        all installed roots                       \n");
+	fprintf(stderr, "                                                               \n");
 	exit(1);
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20091214/d359b1b5/attachment.html>


More information about the darwinbuild-changes mailing list