[darwinbuild-changes] [769] branches/PR-7593824/darwinup

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 11 13:59:32 PST 2010


Revision: 769
          http://trac.macosforge.org/projects/darwinbuild/changeset/769
Author:   wsiegrist at apple.com
Date:     2010-03-11 13:59:31 -0800 (Thu, 11 Mar 2010)
Log Message:
-----------
Add dry run option.

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

Modified: branches/PR-7593824/darwinup/Depot.cpp
===================================================================
--- branches/PR-7593824/darwinup/Depot.cpp	2010-03-11 21:04:12 UTC (rev 768)
+++ branches/PR-7593824/darwinup/Depot.cpp	2010-03-11 21:59:31 UTC (rev 769)
@@ -347,6 +347,7 @@
 
 int Depot::analyze_stage(const char* path, Archive* archive, Archive* rollback,
 						 int* rollback_files) {
+	extern uint32_t dryrun;
 	int res = 0;
 	assert(archive != NULL);
 	assert(rollback != NULL);
@@ -464,7 +465,7 @@
 				join_path(&backup_dirpath, uuidpath, dir);
 				assert(backup_dirpath != NULL);
 				
-				res = mkdir_p(backup_dirpath);
+				if (!dryrun) res = mkdir_p(backup_dirpath);
 				if (res != 0 && errno != EEXIST) {
 					fprintf(stderr, "%s:%d: %s: %s (%d)\n", 
 							__FILE__, __LINE__, backup_dirpath, strerror(errno), errno);
@@ -481,7 +482,7 @@
 				*rollback_files += 1;
 				if (!this->has_file(rollback, actual)) {
 					IF_DEBUG("[analyze]    insert rollback\n");
-					res = this->insert(rollback, actual);
+					if (!dryrun) res = this->insert(rollback, actual);
 				}
 				assert(res == 0);
 
@@ -505,7 +506,7 @@
 						if (!this->has_file(rollback, parent)) {
 							IF_DEBUG("[analyze]      adding parent to rollback: %s \n", 
 									 parent->path());
-							res = this->insert(rollback, parent);
+							if (!dryrun) res = this->insert(rollback, parent);
 						}
 						assert(res == 0);
 						pent = pent->fts_parent;
@@ -514,7 +515,7 @@
 			}
 
 			fprintf(stderr, "%c %s\n", state, file->path());
-			res = this->insert(archive, file);
+			if (!dryrun) res = this->insert(archive, file);
 			assert(res == 0);
 			if (preceding && preceding != actual) delete preceding;
 			if (actual) delete actual;
@@ -648,6 +649,7 @@
 
 
 int Depot::install(Archive* archive) {
+	extern uint32_t dryrun;
 	int res = 0;
 	Archive* rollback = new RollbackArchive();
 
@@ -665,15 +667,15 @@
 	//
 	// The fun starts here
 	//
-	if (res == 0) res = this->begin_transaction();	
+	if (!dryrun && res == 0) res = this->begin_transaction();	
 
 	//
 	// Insert the rollback archive before the new archive to install, thus keeping
 	// the chronology of the serial numbers correct.  We may later choose to delete
 	// the rollback archive if we determine that it was not necessary.
 	//
-	if (res == 0) res = this->insert(rollback);
-	if (res == 0) res = this->insert(archive);
+	if (!dryrun && res == 0) res = this->insert(rollback);
+	if (!dryrun && res == 0) res = this->insert(archive);
 
 	//
 	// Create the stage directory and rollback backing store directories
@@ -683,7 +685,6 @@
 	char* rollback_path = rollback->create_directory(m_archives_path);
 	assert(rollback_path != NULL);
 
-
 	// Extract the archive into its backing store directory
 	if (res == 0) res = archive->extract(archive_path);
 
@@ -693,6 +694,16 @@
 	int rollback_files = 0;
 	if (res == 0) res = this->analyze_stage(archive_path, archive, rollback, &rollback_files);
 	
+	// we can stop now if this is a dry run
+	if (dryrun) {
+		remove_directory(archive_path);
+		remove_directory(rollback_path);
+		free(rollback_path);
+		free(archive_path);
+		(void)this->lock(LOCK_SH);
+		return res;
+	}
+	
 	// If no files were added to the rollback archive, delete the rollback archive.
 	if (res == 0 && rollback_files == 0) {
 		res = this->remove(rollback);
@@ -792,6 +803,7 @@
 }
 
 int Depot::uninstall_file(File* file, void* ctx) {
+	extern uint32_t dryrun;
 	InstallContext* context = (InstallContext*)ctx;
 	int res = 0;
 	char state = ' ';
@@ -825,7 +837,7 @@
 			if (INFO_TEST(preceding->info(), FILE_INFO_NO_ENTRY)) {
 				state = 'R';
 				IF_DEBUG("[uninstall]    removing file\n");
-				if (actual && res == 0) res = actual->remove();
+				if (!dryrun && actual && res == 0) res = actual->remove();
 			} else {
 				// copy the preceding file back out to the system
 				// if it's different from what's already there
@@ -833,13 +845,17 @@
 				if (INFO_TEST(flags, FILE_INFO_DATA_DIFFERS)) {
 					state = 'U';
 					IF_DEBUG("[uninstall]    restoring\n");
-					if (res == 0) res = preceding->install(context->depot->m_archives_path, 
-														   context->depot->m_prefix);
+					if (!dryrun && res == 0) {
+						res = preceding->install(context->depot->m_archives_path, 
+												 context->depot->m_prefix);
+					}
 				} else if (INFO_TEST(flags, FILE_INFO_MODE_DIFFERS) ||
 					   INFO_TEST(flags, FILE_INFO_GID_DIFFERS) ||
 					   INFO_TEST(flags, FILE_INFO_UID_DIFFERS)) {
 					state = 'M';
-					if (res == 0) res = preceding->install_info(context->depot->m_prefix);
+					if (!dryrun && res == 0) {
+						res = preceding->install_info(context->depot->m_prefix);
+					}
 				} else {
 					IF_DEBUG("[uninstall]    no changes; leaving in place\n");
 				}
@@ -847,7 +863,9 @@
 			uint32_t info = preceding->info();
 			if (INFO_TEST(info, FILE_INFO_NO_ENTRY | FILE_INFO_ROLLBACK_DATA) &&
 			    !INFO_TEST(info, FILE_INFO_BASE_SYSTEM)) {
-				if (res == 0) res = context->files_to_remove->add(preceding->serial());
+				if (!dryrun && res == 0) {
+					res = context->files_to_remove->add(preceding->serial());
+				}
 			}
 			delete preceding;
 		} else {
@@ -868,6 +886,7 @@
 int Depot::uninstall(Archive* archive) {
 	extern uint32_t verbosity;
 	extern uint32_t force;
+	extern uint32_t dryrun;
 	int res = 0;
 
 	assert(archive != NULL);
@@ -908,35 +927,39 @@
 	res = this->lock(LOCK_EX);
 	if (res != 0) return res;
 
-	// XXX: this may be superfluous
-	// uninstall_file should be smart enough to do a mtime check...
-	if (res == 0) res = this->prune_directories();
+	if (!dryrun) {
+		// XXX: this may be superfluous
+		// uninstall_file should be smart enough to do a mtime check...
+		if (res == 0) res = this->prune_directories();
 
-	// We do this here to get an exclusive lock on the database.
-	if (res == 0) res = this->begin_transaction();
-	if (res == 0) res = m_db->deactivate_archive(serial);
-	if (res == 0) res = this->commit_transaction();
-
+		// We do this here to get an exclusive lock on the database.
+		if (res == 0) res = this->begin_transaction();
+		if (res == 0) res = m_db->deactivate_archive(serial);
+		if (res == 0) res = this->commit_transaction();
+	}
+	
 	InstallContext context(this, archive);
 	if (res == 0) res = this->iterate_files(archive, &Depot::uninstall_file, &context);
 	
-	if (res == 0) res = this->begin_transaction();
-	uint32_t i;
-	for (i = 0; i < context.files_to_remove->count; ++i) {
-		uint64_t serial = context.files_to_remove->values[i];
-		if (res == 0) res = m_db->delete_file(serial);
-	}
-	if (res == 0) res = this->commit_transaction();
+	if (!dryrun) {
+		if (res == 0) res = this->begin_transaction();
+		uint32_t i;
+		for (i = 0; i < context.files_to_remove->count; ++i) {
+			uint64_t serial = context.files_to_remove->values[i];
+			if (res == 0) res = m_db->delete_file(serial);
+		}
+		if (res == 0) res = this->commit_transaction();
 
-	if (res == 0) res = this->begin_transaction();	
-	if (res == 0) res = this->remove(archive);
-	if (res == 0) res = this->commit_transaction();
+		if (res == 0) res = this->begin_transaction();	
+		if (res == 0) res = this->remove(archive);
+		if (res == 0) res = this->commit_transaction();
 
-	// delete all of the expanded archive backing stores to save disk space
-	if (res == 0) res = this->prune_directories();
+		// delete all of the expanded archive backing stores to save disk space
+		if (res == 0) res = this->prune_directories();
 
-	if (res == 0) res = this->prune_archive(archive);
-
+		if (res == 0) res = this->prune_archive(archive);
+	}
+	
 	if (res == 0) fprintf(stdout, "Uninstalled archive: %llu %s \n",
 						  archive->serial(), archive->name());
 	

Modified: branches/PR-7593824/darwinup/main.cpp
===================================================================
--- branches/PR-7593824/darwinup/main.cpp	2010-03-11 21:04:12 UTC (rev 768)
+++ branches/PR-7593824/darwinup/main.cpp	2010-03-11 21:59:31 UTC (rev 769)
@@ -48,8 +48,9 @@
 	fprintf(stderr, "version: 16                                                    \n");
 	fprintf(stderr, "                                                               \n");
 	fprintf(stderr, "options:                                                       \n");
-	fprintf(stderr, "          -d        do not update dyld cache after (un)install \n");	
+	fprintf(stderr, "          -d        do not update dyld cache                   \n");	
 	fprintf(stderr, "          -f        force operation to succeed at all costs    \n");
+	fprintf(stderr, "          -n        dry run                                    \n");
 	fprintf(stderr, "          -p DIR    operate on roots under DIR (default: /)    \n");
 	fprintf(stderr, "          -v        verbose (use -vv for extra verbosity)      \n");
 	fprintf(stderr, "                                                               \n");
@@ -88,17 +89,16 @@
 // our globals
 uint32_t verbosity;
 uint32_t force;
+uint32_t dryrun;
 
 
 int main(int argc, char* argv[]) {
 	char* progname = strdup(basename(argv[0]));      
-
 	char* path = NULL;
-	
 	bool update_dyld = true;
 
 	int ch;
-	while ((ch = getopt(argc, argv, "dfp:vh")) != -1) {
+	while ((ch = getopt(argc, argv, "dfnp:vh")) != -1) {
 		switch (ch) {
 		case 'd':
 				update_dyld = false;
@@ -107,6 +107,10 @@
 				IF_DEBUG("forcing operations\n");
 				force = 1;
 				break;
+		case 'n':
+				IF_DEBUG("dry run\n");
+				dryrun = 1;
+				break;
 		case 'p':
 				if (optarg[0] != '/') {
 					fprintf(stderr, "Error: -p option must be an absolute path\n");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100311/0485113d/attachment-0001.html>


More information about the darwinbuild-changes mailing list