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

source_changes at macosforge.org source_changes at macosforge.org
Mon Feb 22 16:55:55 PST 2010


Revision: 712
          http://trac.macosforge.org/projects/darwinbuild/changeset/712
Author:   wsiegrist at apple.com
Date:     2010-02-22 16:55:55 -0800 (Mon, 22 Feb 2010)
Log Message:
-----------
Gracefully handle NULL result columns. Provide our own return values that encode whether results were found or not. Implement preceding and superceding queries. Add char arguments to variable WHERE APIs to determine how a column will be compared to the desired value. Store total column size on the Table object so we can accumulate Column offsets and return a proper row_size().

Modified Paths:
--------------
    branches/PR-7489777/darwinup/DB.cpp
    branches/PR-7489777/darwinup/DB.h
    branches/PR-7489777/darwinup/Database.cpp
    branches/PR-7489777/darwinup/Depot.cpp
    branches/PR-7489777/darwinup/Depot.h
    branches/PR-7489777/darwinup/Digest.h
    branches/PR-7489777/darwinup/File.h
    branches/PR-7489777/darwinup/Table.cpp
    branches/PR-7489777/darwinup/Table.h

Modified: branches/PR-7489777/darwinup/DB.cpp
===================================================================
--- branches/PR-7489777/darwinup/DB.cpp	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/DB.cpp	2010-02-23 00:55:55 UTC (rev 712)
@@ -89,7 +89,7 @@
 							  (void**)active,
 							  1,                                 // number of where conditions
 							  this->m_archives_table->column(0), // serial
-							  serial);
+							  '=', serial);
 }
 
 int DarwinupDatabase::update_archive(uint64_t serial, uuid_t uuid, const char* name,
@@ -122,16 +122,93 @@
 	return this->last_insert_id();
 }
 
+File* DarwinupDatabase::make_file(uint8_t* data) {
+	// XXX do this with a for loop and column->type()
+	uint64_t serial;
+	memcpy(&serial, &data[this->file_offset(0)], sizeof(uint64_t));
+	uint64_t archive_serial;
+	memcpy(&archive_serial, &data[this->file_offset(1)], sizeof(uint64_t));
+	
+	IF_DEBUG("make_file offset %d found serial %llu \n", this->file_offset(1), archive_serial);
+	
+	uint64_t info;
+	memcpy(&info, &data[this->file_offset(2)], sizeof(uint64_t));
+	uint64_t mode;
+	memcpy(&mode, &data[this->file_offset(3)], sizeof(uint64_t));
+	uint64_t uid;
+	memcpy(&uid, &data[this->file_offset(4)], sizeof(uint64_t));
+	uint64_t gid;
+	memcpy(&gid, &data[this->file_offset(5)], sizeof(uint64_t));
+	uint64_t size;
+	memcpy(&size, &data[this->file_offset(6)], sizeof(uint64_t));
+
+	Digest* digest = new Digest();
+	digest->m_size = 20; // size of SHA1 hash
+	memcpy(digest->m_data, &data[this->file_offset(7)], 20);
+
+	char* path;
+	memcpy(&path, &data[this->file_offset(8)], sizeof(char*));
+	
+	uint8_t* archive_data;
+	int res = this->get_archive(&archive_data, archive_serial);
+	Archive* archive = NULL;
+	if (FOUND(res)) {
+		archive = this->make_archive(archive_data);
+	} else {
+		fprintf(stderr, "Error: DB::make_file could not find the archive for file: %s: %d \n", path, res);
+		return NULL;
+	}
+	this->m_archives_table->free_result(archive_data);
+	
+	File* result = FileFactory(serial, archive, info, (const char*)path, mode, uid, gid, size, digest);
+	this->m_files_table->free_result(data);
+	
+	return result;
+}
+
+
+
+int DarwinupDatabase::get_next_file(uint8_t** data, File* file, file_starseded_t star) {
+	int res = SQLITE_OK;
+	
+	char comp = '<';
+	const char* name = "file_preceded";
+	int order = ORDER_BY_DESC;
+	if (star == FILE_SUPERSEDED) {
+		comp = '>';
+		name = "file_superseded";
+		order = ORDER_BY_ASC;
+	}
+	res = this->get_row_ordered(name,
+								data,
+								this->m_files_table,
+								this->m_files_table->column(1), // order by archive
+								order,
+								2,
+								this->m_files_table->column(1), // archive
+								comp, file->archive()->serial(),
+								this->m_files_table->column(8), // path
+								'=', file->path());
+	
+	if (res == SQLITE_ROW) return (DB_FOUND | DB_OK);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;
+}
+
 int DarwinupDatabase::get_file_serial_from_archive(Archive* archive, const char* path, uint64_t** serial) {
-	return this->get_value("file_serial__archive_path",
-						   (void**)serial,
-						   this->m_files_table,
-						   this->m_files_table->column(0), // serial
-						   2,                              // number of where conditions
-						   this->m_files_table->column(1), // archive
-						   (uint64_t)archive->serial(),
-						   this->m_files_table->column(8), // path
-						   path);
+	int res = this->get_value("file_serial__archive_path",
+							  (void**)serial,
+							  this->m_files_table,
+							  this->m_files_table->column(0), // serial
+							  2,                              // number of where conditions
+							  this->m_files_table->column(1), // archive
+							  '=', (uint64_t)archive->serial(),
+							  this->m_files_table->column(8), // path
+							  '=', path);
+	
+	if (res == SQLITE_ROW) return (DB_FOUND | DB_OK);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;
 }
 
 int DarwinupDatabase::update_file(uint64_t serial, Archive* archive, uint32_t info, mode_t mode, 
@@ -189,10 +266,10 @@
 					  this->m_files_table,
 					  2,                              // number of where conditions
 					  this->m_files_table->column(1), // archive
-					  (uint64_t)archive->serial(),
+					  '=', (uint64_t)archive->serial(),
 					  this->m_files_table->column(8), // path
-					  path);
-	if (res) {
+					  '=', path);	
+	if (res != SQLITE_ROW) {
 		fprintf(stderr, "Error: unable to count files: %d \n", res);
 		return 0;
 	}
@@ -212,9 +289,9 @@
 						  this->m_archives_table,
 						  1,
 						  this->m_archives_table->column(2), // name
-						  "!<Rollback>");		
+						  '!', "<Rollback>");		
 	}
-	if (res) {
+	if (res != SQLITE_ROW) {
 		fprintf(stderr, "Error: unable to count archives: %d \n", res);
 		return 0;
 	}	
@@ -222,36 +299,48 @@
 }
 
 int DarwinupDatabase::delete_archive(Archive* archive) {
-	return this->del(this->m_archives_table, archive->serial());
+	int res = this->del(this->m_archives_table, archive->serial());
+	if (res != SQLITE_OK) return DB_ERROR;
+	return DB_OK;
 }
 
 int DarwinupDatabase::delete_archive(uint64_t serial) {
-	return this->del(this->m_archives_table, serial) ;
+	int res = this->del(this->m_archives_table, serial);
+	if (res != SQLITE_OK) return DB_ERROR;
+	return DB_OK;
 }
 
 int DarwinupDatabase::delete_empty_archives() {
-	return this->sql("delete_empty_archives", 
-					 "DELETE FROM archives "
-					 "WHERE serial IN "
-					 " (SELECT serial FROM archives "
-					 "  WHERE serial NOT IN "
-					 "   (SELECT DISTINCT archive FROM files));");	
+	int res = this->sql("delete_empty_archives", 
+						"DELETE FROM archives "
+						"WHERE serial IN "
+						" (SELECT serial FROM archives "
+						"  WHERE serial NOT IN "
+						"   (SELECT DISTINCT archive FROM files));");	
+	if (res != SQLITE_OK) return DB_ERROR;
+	return DB_OK;
 }
 
 int DarwinupDatabase::delete_file(File* file) {
-	return this->del(this->m_files_table, file->serial());
+	int res = this->del(this->m_files_table, file->serial());
+	if (res != SQLITE_OK) return DB_ERROR;
+	return DB_OK;
 }
 
 int DarwinupDatabase::delete_file(uint64_t serial) {
-	return this->del(this->m_files_table, serial);
+	int res = this->del(this->m_files_table, serial);
+	if (res != SQLITE_OK) return DB_ERROR;
+	return DB_OK;
 }
 
 int DarwinupDatabase::delete_files(Archive* archive) {
-	return this->del("delete_files__archive",
-					 this->m_files_table,
-					 1,                               // number of where conditions
-					 this->m_files_table->column(1),  // archive
-					 (uint64_t)archive->serial());
+	int res = this->del("delete_files__archive",
+						this->m_files_table,
+						1,                               // number of where conditions
+						this->m_files_table->column(1),  // archive
+						'=', (uint64_t)archive->serial());
+	if (res != SQLITE_OK) return DB_ERROR;
+	return DB_OK;
 }
 
 
@@ -262,19 +351,25 @@
 							   this->m_archives_table->column(0), // serial
 							   1,
 							   this->m_archives_table->column(4), // active
-							   (uint64_t)0);
-	return res;
+							   '=', (uint64_t)0);
+	if (res == SQLITE_DONE && *count) return (DB_OK & DB_FOUND);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;
 }
 
 int DarwinupDatabase::get_file_serials(uint64_t** serials, uint32_t* count) {
-	return this->get_column("file_serials", (void**)serials, count, 
-							this->m_files_table,
-							this->m_files_table->column(0),
-							0);
+	int res = this->get_column("file_serials", (void**)serials, count, 
+							   this->m_files_table,
+							   this->m_files_table->column(0),
+							   0);
+	if (res == SQLITE_DONE && *count) return (DB_OK & DB_FOUND);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;	
 }
 
 
 Archive* DarwinupDatabase::make_archive(uint8_t* data) {
+	// XXX do this with a for loop and column->type()
 	uint64_t serial;
 	memcpy(&serial, &data[this->archive_offset(0)], sizeof(uint64_t));
 	uuid_t* uuid;
@@ -292,30 +387,40 @@
 }
 
 int DarwinupDatabase::get_archive(uint8_t** data, uuid_t uuid) {
-	return this->get_row("archive__uuid",
-						 data,
-						 this->m_archives_table,
-						 1,
-						 this->m_archives_table->column(1), // uuid
-						 uuid, sizeof(uuid_t));
+	int res = this->get_row("archive__uuid",
+							data,
+							this->m_archives_table,
+							1,
+							this->m_archives_table->column(1), // uuid
+							'=', uuid, sizeof(uuid_t));
+	if (res == SQLITE_ROW) return (DB_FOUND | DB_OK);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;	
 }
 
 int DarwinupDatabase::get_archive(uint8_t** data, uint64_t serial) {
-	return this->get_row("archive__serial",
-						 data,
-						 this->m_archives_table,
-						 1,
-						 this->m_archives_table->column(0), // serial
-						 serial);
+	IF_DEBUG("get_archive serial: %llu \n", serial);
+	int res = this->get_row("archive__serial",
+							data,
+							this->m_archives_table,
+							1,
+							this->m_archives_table->column(0), // serial
+							'=', serial);
+	if (res == SQLITE_ROW) return (DB_FOUND | DB_OK);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;	
 }
 
 int DarwinupDatabase::get_archive(uint8_t** data, const char* name) {
-	return this->get_row("archive__name",
-						 data,
-						 this->m_archives_table,
-						 1,
-						 this->m_archives_table->column(2), // name
-						 name);
+	int res = this->get_row("archive__name",
+							data,
+							this->m_archives_table,
+							1,
+							this->m_archives_table->column(2), // name
+							'=', name);
+	if (res == SQLITE_ROW) return (DB_FOUND | DB_OK);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;	
 }
 
 int DarwinupDatabase::get_archive(uint8_t** data, archive_keyword_t keyword) {
@@ -333,22 +438,17 @@
 								order,
 								1,
 								this->m_archives_table->column(2), // name
-								"!<Rollback>");
+								'!', "<Rollback>");
 	
-	return res;
+	if (res == SQLITE_ROW) return (DB_FOUND | DB_OK);
+	if (res == SQLITE_DONE) return DB_OK;
+	return DB_ERROR;	
 }
 
 int DarwinupDatabase::archive_offset(int column) {
 	return this->m_archives_table->offset(column);
 }
 
-
-/*
-get_all_archives(include_rollbacks?)
- 
-get_files(archive)
-
-
-*/
-
-
+int DarwinupDatabase::file_offset(int column) {
+	return this->m_files_table->offset(column);
+}

Modified: branches/PR-7489777/darwinup/DB.h
===================================================================
--- branches/PR-7489777/darwinup/DB.h	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/DB.h	2010-02-23 00:55:55 UTC (rev 712)
@@ -43,8 +43,14 @@
 #include "Digest.h"
 #include "File.h"
 
+// return code bits
+#define DB_OK        0x0000
+#define DB_ERROR     0x0001
+#define DB_FOUND     0x0010
 
+#define FOUND(x)  ((x & DB_FOUND) && !(x & DB_ERROR))
 
+
 /**
  *
  * Darwinup database abstraction. This class is responsible
@@ -80,8 +86,11 @@
 	int      delete_archive(uint64_t serial);
 
 	// Files
+	File*    make_file(uint8_t* data);
+	int      get_next_file(uint8_t** data, File* file, file_starseded_t star);
 	int      get_file_serials(uint64_t** serials, uint32_t* count);
 	int      get_file_serial_from_archive(Archive* archive, const char* path, uint64_t** serial);
+	int      file_offset(int column);
 	int      update_file(uint64_t serial, Archive* archive, uint32_t info, mode_t mode, 
 						 uid_t uid, gid_t gid, Digest* digest, const char* path);
 	uint64_t insert_file(uint32_t info, mode_t mode, uid_t uid, gid_t gid, 

Modified: branches/PR-7489777/darwinup/Database.cpp
===================================================================
--- branches/PR-7489777/darwinup/Database.cpp	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/Database.cpp	2010-02-23 00:55:55 UTC (rev 712)
@@ -304,6 +304,7 @@
     fprintf(stderr, "DEBUG: sql: %s \n", sqlite3_sql(stmt)); \
     for (uint32_t i=0; i<count; i++) { \
         Column* col = va_arg(args, Column*); \
+        va_arg(args, int); \
         uint8_t* bdata = NULL; \
         uint32_t bsize = 0; \
         char* tval; \
@@ -313,7 +314,6 @@
                 break; \
             case TYPE_TEXT: \
                 tval = va_arg(args, char*); \
-                if (tval[0] == '!' || tval[0] == '>' || tval[0] == '<') tval++; \
                 res = sqlite3_bind_text(stmt, param++, tval, -1, SQLITE_STATIC); \
                 break; \
             case TYPE_BLOB: \
@@ -383,6 +383,12 @@
 			IF_DEBUG("store_column used=%u output(%p) = %s \n", 
 					 (uint32_t)used, *(char**)output, *(char**)output);
 			break;
+		case SQLITE_NULL:
+			// result row has a NULL value which is okay
+			IF_DEBUG("store_column got a NULL column value for: %d \n", column);
+			*(const char**)output = NULL;
+			used = sizeof(char*);
+			break;
 		default:
 			fprintf(stderr, "Error: unhandled column type in Database::store_column(): %d \n", 
 					type);
@@ -417,7 +423,6 @@
 			*used = current - output;
 			IF_DEBUG("step_once after store used(%p) = %u \n", used, *used);
 		}
-		res = SQLITE_OK;
 	}
 
 	return res;
@@ -430,12 +435,12 @@
 	uint8_t* current = *(uint8_t**)output;
 	*count = 0;
 	IF_DEBUG("rowsize = %u \n", rowsize);
-	int res = SQLITE_OK;
-	while (res == SQLITE_OK) {
+	int res = SQLITE_ROW;
+	while (res == SQLITE_ROW) {
 		current = *(uint8_t**)output + total_used;
 		IF_DEBUG("calling step_once with current(%p) \n", current);
 		res = this->step_once(stmt, current, &used);
-		if (res == SQLITE_OK) (*count)++;
+		if (res == SQLITE_ROW) (*count)++;
 		total_used += used;
 		IF_DEBUG("stepped: used = %u total_used = %u size = %u \n", used, total_used, size);
 		if (total_used >= (size - rowsize)) {
@@ -461,7 +466,7 @@
 	uint32_t size = value_column->size();
 	*output = malloc(size);
 	res = this->step_once(stmt, (uint8_t*)*output, NULL);
-	IF_DEBUG("get_value output(%p) = %llu \n", *output, **(uint64_t**)output);
+	IF_DEBUG("get_value: res = %d output(%p) = %llu \n", res, *output, **(uint64_t**)output);
 	sqlite3_reset(stmt);
 	cache_release_value(m_statement_cache, &stmt);
 	return res;

Modified: branches/PR-7489777/darwinup/Depot.cpp
===================================================================
--- branches/PR-7489777/darwinup/Depot.cpp	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/Depot.cpp	2010-02-23 00:55:55 UTC (rev 712)
@@ -150,7 +150,7 @@
 	uint8_t* data;
 	
 	res = this->m_db2->get_archive(&data, uuid);
-	if (res == 0) archive = this->m_db2->make_archive(data);
+	if (FOUND(res)) archive = this->m_db2->make_archive(data);
 	return archive;
 }
 
@@ -162,7 +162,7 @@
 	uint8_t* data;
 	
 	res = this->m_db2->get_archive(&data, serial);
-	if (res == 0) archive = this->m_db2->make_archive(data);
+	if (FOUND(res)) archive = this->m_db2->make_archive(data);
 
 	return archive;
 }
@@ -175,7 +175,7 @@
 	uint8_t* data;
 	
 	res = this->m_db2->get_archive(&data, name);
-	if (res == 0) archive = this->m_db2->make_archive(data);
+	if (FOUND(res)) archive = this->m_db2->make_archive(data);
 	return archive;
 }
 
@@ -185,11 +185,12 @@
 	uint8_t* data;
 	
 	res = this->m_db2->get_archive(&data, keyword);
-	if (res == 0) archive = this->m_db2->make_archive(data);	
+	if (FOUND(res)) archive = this->m_db2->make_archive(data);	
 	return archive;	
 }
 
 // create a new Archive from a database row
+// XXX this should get moved to DB
 Archive* Depot::archive(sqlite3_stmt* stmt) {
 	uuid_t uuid;
 	uint64_t serial = sqlite3_column_int64(stmt, 0);
@@ -365,6 +366,7 @@
 			File* actual = FileFactory(actpath);
 
 			File* preceding = this->file_preceded_by(file);
+			if (preceding) IF_DEBUG("[PRECED] %llu %s \n", preceding->serial(), preceding->path());
 			
 			if (actual == NULL) {
 				// No actual file exists already, so we create a placeholder.
@@ -529,6 +531,7 @@
 	int res = 0;
 
 	IF_DEBUG("[backup] backup_file: %s , %s \n", file->path(), context->archive->m_name);
+	IF_DEBUG("info = %d \n", file->info());
 
 	if (INFO_TEST(file->info(), FILE_INFO_ROLLBACK_DATA)) {
 	        char *path;        // the file's path
@@ -739,10 +742,12 @@
 		IF_DEBUG("[uninstall]    changes since install; skipping\n");
 	} else {
 		File* superseded = context->depot->file_superseded_by(file);
+		if (superseded) IF_DEBUG("[SUPER] %llu %s \n", superseded->serial(), superseded->path());
 		if (superseded == NULL) {
 			// no one's using this file anymore
 			File* preceding = context->depot->file_preceded_by(file);
 			assert(preceding != NULL);
+			IF_DEBUG("[PRECED] %llu %s \n", preceding->serial(), preceding->path());
 			if (INFO_TEST(preceding->info(), FILE_INFO_NO_ENTRY)) {
 				state = 'R';
 				IF_DEBUG("[uninstall]    removing file\n");
@@ -930,79 +935,18 @@
 }
 
 
-File* Depot::file_star_eded_by(File* file, sqlite3_stmt* stmt) {
-	assert(file != NULL);
-	assert(file->archive() != NULL);
-	
-	File* result = NULL;
-	uint64_t serial = 0;
-	int res = 0;
-	if (stmt && res == 0) {
-		if (res == 0) res = sqlite3_bind_int64(stmt, 1, file->archive()->serial());
-		if (res == 0) res = sqlite3_bind_text(stmt, 2, file->path(), -1, SQLITE_STATIC);
-		if (res == 0) res = sqlite3_step(stmt);
-		switch (res) {
-			case SQLITE_DONE:
-				serial = 0;
-				break;
-			case SQLITE_ROW:
-				{
-				int i = 0;
-				uint64_t serial = sqlite3_column_int64(stmt, i++);
-				uint64_t archive_serial = sqlite3_column_int64(stmt, i++);
-				uint32_t info = sqlite3_column_int(stmt, i++);
-				const unsigned char* path = sqlite3_column_text(stmt, i++);
-				mode_t mode = sqlite3_column_int(stmt, i++);
-				uid_t uid = sqlite3_column_int(stmt, i++);
-				gid_t gid = sqlite3_column_int(stmt, i++);
-				off_t size = sqlite3_column_int64(stmt, i++);
-				const void* blob = sqlite3_column_blob(stmt, i);
-				int blobsize = sqlite3_column_bytes(stmt, i++);
-
-				Digest* digest = NULL;
-				if (blobsize > 0) {
-					digest = new Digest();
-					digest->m_size = blobsize;
-					memcpy(digest->m_data, blob, ((size_t)blobsize < sizeof(digest->m_data)) ? blobsize : sizeof(digest->m_data));
-				}
-
-				Archive* archive = this->archive(archive_serial);
-
-				result = FileFactory(serial, archive, info, (const char*)path, mode, uid, gid, size, digest);
-				}
-				break;
-			default:
-				fprintf(stderr, "%s:%d: unexpected SQL error: %d\n", __FILE__, __LINE__, res);
-				break;
-		}
-		sqlite3_reset(stmt);
-	} else {
-		fprintf(stderr, "%s:%d: unexpected SQL error: %d\n", __FILE__, __LINE__, res);
-	}
-	
-	return result;
-}
-
 File* Depot::file_superseded_by(File* file) {
-	static sqlite3_stmt* stmt = NULL;
-	if (stmt == NULL && m_db) {
-		// archive which installed this file immediately after
-		const char* query = "SELECT serial, archive, info, path, mode, uid, gid, size, digest FROM files WHERE archive>? AND path=? ORDER BY archive ASC LIMIT 1";
-		int 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);
-	}
-	return this->file_star_eded_by(file, stmt);
+	uint8_t* data;
+	int res = this->m_db2->get_next_file(&data, file, FILE_SUPERSEDED);
+	if (FOUND(res)) return this->m_db2->make_file(data);
+	return NULL;
 }
 
 File* Depot::file_preceded_by(File* file) {
-	static sqlite3_stmt* stmt = NULL;
-	if (stmt == NULL && m_db) {
-		// archive which installed this file immediately before
-		const char* query = "SELECT serial, archive, info, path, mode, uid, gid, size, digest FROM files WHERE archive<? AND path=? ORDER BY archive DESC LIMIT 1";
-		int 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);
-	}
-	return this->file_star_eded_by(file, stmt);
+	uint8_t* data;
+	int res = this->m_db2->get_next_file(&data, file, FILE_PRECEDED);
+	if (FOUND(res)) return this->m_db2->make_file(data);
+	return NULL;
 }
 
 int Depot::check_consistency() {
@@ -1122,15 +1066,13 @@
 	if (this->has_file(archive, file)) {
 		do_update = 1;
 		res = this->m_db2->get_file_serial_from_archive(archive, relpath, &serial);
-		if (!serial) {
-			fprintf(stderr, "Error: unable to find file from archive %llu at path %s \n", 
-					archive->serial(), relpath);
+		if (!serial || !FOUND(res)) {
+			fprintf(stderr, "Error: unable to find file from archive %llu at path %s: %p %llu %d \n", 
+					archive->serial(), relpath, serial, *serial, res);
 			return 1;
 		}
-		if (res == SQLITE_OK) {
-			res = m_db2->update_file(*serial, archive, file->info(), file->mode(), file->uid(), file->gid(),
+		res = m_db2->update_file(*serial, archive, file->info(), file->mode(), file->uid(), file->gid(),
 									 file->digest(), relpath);
-		}
 	} else {
 		file->m_serial = m_db2->insert_file(file->info(), file->mode(), file->uid(), file->gid(), 
 											file->digest(), archive, relpath);

Modified: branches/PR-7489777/darwinup/Depot.h
===================================================================
--- branches/PR-7489777/darwinup/Depot.h	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/Depot.h	2010-02-23 00:55:55 UTC (rev 712)
@@ -143,7 +143,6 @@
 	
 	File*		file_superseded_by(File* file);
 	File*		file_preceded_by(File* file);
-	File*		file_star_eded_by(File* file, sqlite3_stmt* stmt);
 
 	int		check_consistency();
 

Modified: branches/PR-7489777/darwinup/Digest.h
===================================================================
--- branches/PR-7489777/darwinup/Digest.h	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/Digest.h	2010-02-23 00:55:55 UTC (rev 712)
@@ -93,6 +93,7 @@
 	uint32_t	m_size;
 	
 	friend struct Depot;
+	friend struct DarwinupDatabase;
 };
 
 ////

Modified: branches/PR-7489777/darwinup/File.h
===================================================================
--- branches/PR-7489777/darwinup/File.h	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/File.h	2010-02-23 00:55:55 UTC (rev 712)
@@ -39,6 +39,11 @@
 #include <sys/stat.h>
 #include <fts.h>
 
+enum file_starseded_t {
+	FILE_SUPERSEDED,
+	FILE_PRECEDED
+};
+
 //
 // FILE_INFO flags stored in the database
 //

Modified: branches/PR-7489777/darwinup/Table.cpp
===================================================================
--- branches/PR-7489777/darwinup/Table.cpp	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/Table.cpp	2010-02-23 00:55:55 UTC (rev 712)
@@ -56,6 +56,7 @@
 	m_column_max    = 1;
 	m_column_count  = 0;
 	m_columns       = (Column**)malloc(sizeof(Column*) * m_column_max);
+	m_columns_size  = 0; 
 	m_result_max    = 1;
 	m_result_count  = 0;
 	m_results       = (uint8_t**)malloc(sizeof(uint8_t*) * m_result_max);
@@ -75,6 +76,7 @@
 	m_column_max    = 1;
 	m_column_count  = 0;
 	m_columns       = (Column**)malloc(sizeof(Column*) * m_column_max);
+	m_columns_size  = 0; 
 	m_result_max    = 1;
 	m_result_count  = 0;
 	m_results       = (uint8_t**)malloc(sizeof(uint8_t*) * m_result_max);
@@ -124,7 +126,7 @@
 }
 
 uint32_t Table::row_size() {
-	return m_column_count*8;
+	return m_columns_size;
 }
 
 const Column** Table::columns() {
@@ -133,10 +135,9 @@
 
 
 int Table::add_column(Column* c) {
-	// accumulate offsets for columns
-	static int offset = 0;
-	c->m_offset = offset;
-	offset += c->size();
+	// accumulate offsets for columns in m_columns_size
+	c->m_offset = this->m_columns_size;
+	this->m_columns_size += c->size();
 	
 	// reallocate if needed
 	if (m_column_count >= m_column_max) {
@@ -274,30 +275,22 @@
 
 #define __where_va_columns \
 	char tmpstr[256]; \
-    char* val; \
-    const char* op = "="; \
+    char tmp_op = '='; \
+    char op = '='; \
+    char not_op = ' '; \
 	int len; \
 	for (uint32_t i=0; i < count; i++) { \
         fprintf(stderr, "DEBUG: __where_va i=%u \n", i); \
 		Column* col = va_arg(args, Column*); \
 		fprintf(stderr, "DEBUG: __where_va col %p \n", col); \
-        if (col->type() == SQLITE_TEXT) { \
-            val = va_arg(args, char*); \
-            switch (val[0]) { \
-            case '!': \
-                op = "!="; \
-                break; \
-            case '>': \
-                op = ">"; \
-                break; \
-            case '<': \
-                op = "<"; \
-                break; \
-            } \
-		} else { \
-	        va_arg(args, void*); \
+        tmp_op = va_arg(args, int); \
+        if (tmp_op == '!') { \
+            not_op = tmp_op; \
+        } else { \
+            op = tmp_op; \
         } \
-		len = snprintf(tmpstr, 256, " AND %s%s?", col->name(), op); \
+        va_arg(args, void*); \
+		len = snprintf(tmpstr, 256, " AND %s%c%c?", col->name(), not_op, op); \
 		if (len >= 255) { \
 			fprintf(stderr, "Error: column name is too big (limit: 248): %s\n", col->name()); \
 			return NULL; \

Modified: branches/PR-7489777/darwinup/Table.h
===================================================================
--- branches/PR-7489777/darwinup/Table.h	2010-02-20 00:44:59 UTC (rev 711)
+++ branches/PR-7489777/darwinup/Table.h	2010-02-23 00:55:55 UTC (rev 712)
@@ -77,7 +77,7 @@
 	int            free_row(uint8_t* row);
 	
 	char*          m_name;
-	
+
 	char*          m_create_sql;
 	char*          m_insert_sql;
 	char*          m_update_sql;
@@ -86,6 +86,7 @@
 	Column**       m_columns;
 	uint32_t       m_column_count;
 	uint32_t       m_column_max;
+	int            m_columns_size;
 	
 	sqlite3_stmt*  m_prepared_insert;
 	sqlite3_stmt*  m_prepared_update;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100222/ca1ddac6/attachment-0001.html>


More information about the darwinbuild-changes mailing list