[darwinbuild-changes] [709] branches/PR-7489777/darwinup

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 19 15:44:16 PST 2010


Revision: 709
          http://trac.macosforge.org/projects/darwinbuild/changeset/709
Author:   wsiegrist at apple.com
Date:     2010-02-19 15:44:16 -0800 (Fri, 19 Feb 2010)
Log Message:
-----------
Implement count_archives

Modified Paths:
--------------
    branches/PR-7489777/darwinup/DB.cpp
    branches/PR-7489777/darwinup/DB.h
    branches/PR-7489777/darwinup/Depot.cpp
    branches/PR-7489777/darwinup/Depot.h

Modified: branches/PR-7489777/darwinup/DB.cpp
===================================================================
--- branches/PR-7489777/darwinup/DB.cpp	2010-02-19 23:07:41 UTC (rev 708)
+++ branches/PR-7489777/darwinup/DB.cpp	2010-02-19 23:44:16 UTC (rev 709)
@@ -182,7 +182,6 @@
 }
 
 uint64_t DarwinupDatabase::count_files(Archive* archive, const char* path) {
-
 	int res = SQLITE_OK;
 	uint64_t* c;
 	res = this->count("count_files",
@@ -193,9 +192,34 @@
 					  (uint64_t)archive->serial(),
 					  this->m_files_table->column(8), // path
 					  path);
+	if (res) {
+		fprintf(stderr, "Error: unable to count files: %d \n", res);
+		return 0;
+	}
 	return *c;
 }
 
+uint64_t DarwinupDatabase::count_archives(bool include_rollbacks) {
+	int res = SQLITE_OK;
+	uint64_t* c;
+	if (include_rollbacks) {
+		res = this->count("count_archives",
+						  (void**)&c,
+						  this->m_archives_table, 0);				
+	} else {
+		res = this->count("count_archives_norollback",
+						  (void**)&c,
+						  this->m_archives_table,
+						  1,
+						  this->m_archives_table->column(2), // name
+						  "!<Rollback>");		
+	}
+	if (res) {
+		fprintf(stderr, "Error: unable to count archives: %d \n", res);
+		return 0;
+	}	
+	return *c;	
+}
 
 int DarwinupDatabase::delete_archive(Archive* archive) {
 	return this->del(this->m_archives_table, archive->serial());
@@ -321,8 +345,6 @@
 
 /*
 get_all_archives(include_rollbacks?)
-
-count_archives(include_rollbacks?)
  
 get_files(archive)
 

Modified: branches/PR-7489777/darwinup/DB.h
===================================================================
--- branches/PR-7489777/darwinup/DB.h	2010-02-19 23:07:41 UTC (rev 708)
+++ branches/PR-7489777/darwinup/DB.h	2010-02-19 23:44:16 UTC (rev 709)
@@ -60,6 +60,7 @@
 	void init_schema();
 	
 	uint64_t count_files(Archive* archive, const char* path);
+	uint64_t count_archives(bool include_rollbacks);
 	
 	// Archives
 	Archive* make_archive(uint8_t* data);

Modified: branches/PR-7489777/darwinup/Depot.cpp
===================================================================
--- branches/PR-7489777/darwinup/Depot.cpp	2010-02-19 23:07:41 UTC (rev 708)
+++ branches/PR-7489777/darwinup/Depot.cpp	2010-02-19 23:44:16 UTC (rev 709)
@@ -237,7 +237,7 @@
 	return Depot::archive((archive_name_t)arg);
 }
 
-Archive** Depot::get_all_archives(size_t* count) {
+Archive** Depot::get_all_archives(uint64_t* count) {
 	extern uint32_t verbosity;
 	int res = 0;
 	*count = this->count_archives();
@@ -264,32 +264,15 @@
 	return list;	
 }
 
-size_t Depot::count_archives() {
+uint64_t Depot::count_archives() {
 	extern uint32_t verbosity;
-	int res = 0;
-	size_t count = 0;
-	static sqlite3_stmt* stmt = NULL;
-	if (stmt == NULL && m_db) {
-		const char* query = "SELECT count(*) FROM archives WHERE name != '<Rollback>'";
-		if (verbosity & VERBOSE_DEBUG) {
-			query = "SELECT count(*) FROM archives";
-		}
-		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) {
-			count = sqlite3_column_int64(stmt, 0);
-		}
-		sqlite3_reset(stmt);
-	}
-	return count;
+	uint64_t c = this->m_db2->count_archives(verbosity & VERBOSE_DEBUG);
+	return c;
 }
 
 int Depot::iterate_archives(ArchiveIteratorFunc func, void* context) {
 	int res = 0;
-	size_t count = 0;
+	uint64_t count = 0;
 	Archive** list = this->get_all_archives(&count);
 	for (size_t i = 0; i < count; i++) {
 		if (list[i]) {
@@ -1220,7 +1203,7 @@
 int Depot::process_archive(const char* command, const char* arg) {
 	extern uint32_t verbosity;
 	int res = 0;
-	size_t count = 0;
+	uint64_t count = 0;
 	Archive** list = NULL;
 	
 	if (strncasecmp(arg, "all", 3) == 0) {

Modified: branches/PR-7489777/darwinup/Depot.h
===================================================================
--- branches/PR-7489777/darwinup/Depot.h	2010-02-19 23:07:41 UTC (rev 708)
+++ branches/PR-7489777/darwinup/Depot.h	2010-02-19 23:44:16 UTC (rev 709)
@@ -72,8 +72,8 @@
 	Archive* get_archive(const char* arg);
 
 	// returns a list of Archive*. Caller must free the list. 
-	Archive** get_all_archives(size_t *count);
-	size_t count_archives();
+	Archive** get_all_archives(uint64_t *count);
+	uint64_t count_archives();
 	
 	int dump();
 	static int dump_archive(Archive* archive, void* context);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100219/827b6d9b/attachment.html>


More information about the darwinbuild-changes mailing list