[darwinbuild-changes] [873] branches/PR-8416637/darwinup

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 16 11:13:53 PDT 2010


Revision: 873
          http://trac.macosforge.org/projects/darwinbuild/changeset/873
Author:   wsiegrist at apple.com
Date:     2010-09-16 11:13:51 -0700 (Thu, 16 Sep 2010)
Log Message:
-----------
Use macros to remove magic numbers from Depot

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

Modified: branches/PR-8416637/darwinup/Depot.cpp
===================================================================
--- branches/PR-8416637/darwinup/Depot.cpp	2010-09-14 23:26:57 UTC (rev 872)
+++ branches/PR-8416637/darwinup/Depot.cpp	2010-09-16 18:13:51 UTC (rev 873)
@@ -103,9 +103,9 @@
 	m_db = new DarwinupDatabase(m_database_path);
 	if (!m_db || !m_db->is_connected()) {
 		fprintf(stderr, "Error: unable to connect to database.\n");
-		return 1;
+		return DB_ERROR;
 	}
-	return 0;
+	return DB_OK;
 }
 
 int Depot::create_storage() {
@@ -138,7 +138,7 @@
 		perror(m_downloads_path);
 		return res;
 	}
-	return 0;
+	return DEPOT_OK;
 }
 
 // Initialize the depot
@@ -148,7 +148,7 @@
 	// initialization requires all these paths to be set
 	if (!(m_prefix && m_depot_path && m_database_path && 
 		  m_archives_path && m_downloads_path)) {
-		return -1;
+		return DEPOT_ERROR;
 	}
 	
 	if (writable) {
@@ -172,11 +172,11 @@
 	res = stat(m_database_path, &sb);
 	if (!writable && res == -1 && (errno == ENOENT || errno == ENOTDIR)) {
 		// depot does not exist
-		return -2; 
+		return DEPOT_NOT_EXIST; 
 	}
 	if (!writable && res == -1 && errno == EACCES) {
 		// permission denied
-		return -3;
+		return DEPOT_PERM_DENIED;
 	}
 
 	// take an exclusive lock
@@ -484,7 +484,7 @@
 						fprintf(stderr, FILE_OBJ_CHANGE_ERROR, path, 
 								FILE_TYPE_STRING(file_type),
 								FILE_TYPE_STRING(actual_type));
-						return -2;
+						return DEPOT_OBJ_CHANGE;
 					}
 					state = 'U';
 				}
@@ -687,20 +687,25 @@
 			uuid_unparse_upper(archive->uuid(), uuid);
 			fprintf(stdout, "%s\n", uuid);
 		} else {
-			fprintf(stderr, "Error: Install failed. Rolling back installation.\n");
-			res = this->uninstall(archive);
-			if (res) {
-				fprintf(stderr, "Error: Unable to rollback installation. "
-						"Your system is in an inconsistent state! File a bug!\n");
-			} else {
-				fprintf(stdout, "Rollback successful.\n");
+			fprintf(stderr, "Error: Install failed.\n");				
+			if (res != DEPOT_OBJ_CHANGE) {
+				// object change errors come from analyze stage,
+				// so there is no installation to roll back
+				fprintf(stderr, "Rolling back installation.\n");
+				res = this->uninstall(archive);
+				if (res) {
+					fprintf(stderr, "Error: Unable to rollback installation. "
+							"Your system is in an inconsistent state! File a bug!\n");
+				} else {
+					fprintf(stdout, "Rollback successful.\n");
+				}
 			}
-			res = 1;
+			res = DEPOT_ERROR;
 		}
 	} else {
-		fprintf(stdout, "Error: unable to load \"%s\". Either the path is invalid or"
+		fprintf(stdout, "Error: unable to load \"%s\". Either the path is missing, invalid or"
 				         " the file is in an unknown format.\n", path);
-		return -1;
+		return DEPOT_ERROR;
 	}
 
 	return res;
@@ -868,7 +873,7 @@
 	// We never uninstall a file that was part of the base system
 	if (INFO_TEST(file->info(), FILE_INFO_BASE_SYSTEM)) {
 		IF_DEBUG("[uninstall]    base system; skipping\n");
-		return 0;
+		return DEPOT_OK;
 	}
 	
 	char* actpath;
@@ -954,10 +959,10 @@
 		// if in debug mode, get_all_archives returns rollbacks too, so just ignore
 		if (verbosity & VERBOSE_DEBUG) {
 			fprintf(stderr, "[uninstall] skipping uninstall since archive is a rollback.\n");
-			return 0;
+			return DEPOT_OK;
 		}
 		fprintf(stderr, "%s:%d: cannot uninstall a rollback archive.\n", __FILE__, __LINE__);
-		return -1;
+		return DEPOT_ERROR;
 	}
 
 	/** 
@@ -981,7 +986,7 @@
 				"happen.\n"
 				"-------------------------------------------------------------------------------\n",
 				archive->name(), archive->build(), m_build);
-		return 9999;
+		return DEPOT_BUILD_MISMATCH;
 	}
 
 	if (res != 0) return res;
@@ -1040,7 +1045,7 @@
 		fprintf(stdout, "R ");
 	}
 	file->print(stdout);
-	return 0;
+	return DEPOT_OK;
 }
 
 void Depot::archive_header() {
@@ -1076,7 +1081,7 @@
 	fprintf((FILE*)context, "%-6llu %-36s  %-12s  %-7s  %s\n", 
 			serial, uuid, date, (archive->build()?archive->build():""), archive->name());
 	
-	return 0;
+	return DEPOT_OK;
 }
 
 int Depot::list() {
@@ -1123,7 +1128,7 @@
 	extern uint32_t verbosity;
 	if (verbosity & VERBOSE_DEBUG) fprintf((FILE*)context, "%04x ", file->info());
 	file->print((FILE*)context);
-	return 0;
+	return DEPOT_OK;
 }
 
 int Depot::files(Archive* archive) {
@@ -1335,7 +1340,7 @@
 	}
 
 	free(path);
-	return 0;
+	return DEPOT_OK;
 }
 
 int Depot::has_file(Archive* archive, File* file) {
@@ -1414,7 +1419,7 @@
 	for (size_t i = 0; i < count; i++) {
 		if (!list[i]) {
 			fprintf(stdout, "Archive not found: %s\n", archspec);
-			return -1;
+			return DEPOT_ERROR;
 		}
 		if (verbosity & VERBOSE_DEBUG) {
 			char uuid[37];
@@ -1436,13 +1441,13 @@
 		(strncasecmp(archspec, "superseded", 10) == 0 && strlen(archspec) == 10)) {
 		fprintf(stderr, "Error: keywords 'all' and 'superseded' cannot be used with the"
 				" rename command.\n");
-		return -2;
+		return DEPOT_USAGE_ERROR;
 	}
 	
 	Archive* archive = this->get_archive(archspec);
 	if (!archive) {
 		fprintf(stdout, "Archive not found: %s\n", archspec);
-		return -1;
+		return DEPOT_NOT_EXIST;
 	}
 	
 	char uuid[37];
@@ -1453,7 +1458,7 @@
 
 	if (!name || strlen(name) == 0) {
 		fprintf(stderr, "Error: invalid name: '%s'\n", name);
-		return -3;
+		return DEPOT_ERROR;
 	}
 	
 	free(archive->m_name);

Modified: branches/PR-8416637/darwinup/Depot.h
===================================================================
--- branches/PR-8416637/darwinup/Depot.h	2010-09-14 23:26:57 UTC (rev 872)
+++ branches/PR-8416637/darwinup/Depot.h	2010-09-16 18:13:51 UTC (rev 873)
@@ -39,6 +39,15 @@
 #include "DB.h"
 #include "Archive.h"
 
+#define DEPOT_OK              0
+#define DEPOT_ERROR          -1
+#define DEPOT_NOT_EXIST      -2
+#define DEPOT_PERM_DENIED    -3
+#define DEPOT_OBJ_CHANGE     -4
+#define DEPOT_BUILD_MISMATCH -5
+#define DEPOT_USAGE_ERROR    -6
+
+
 struct Archive;
 struct File;
 struct DarwinupDatabase;

Modified: branches/PR-8416637/darwinup/main.cpp
===================================================================
--- branches/PR-8416637/darwinup/main.cpp	2010-09-14 23:26:57 UTC (rev 872)
+++ branches/PR-8416637/darwinup/main.cpp	2010-09-16 18:13:51 UTC (rev 873)
@@ -183,14 +183,14 @@
 	// list handles args optional and in special ways
 	if (strcmp(argv[0], "list") == 0) {
 		res = depot->initialize(false);
-		if (res == -2) {
+		if (res == DEPOT_NOT_EXIST) {
 			// we are not asking to write, 
 			// but no depot exists yet either,
 			// so print an empty list
 			depot->archive_header();
 			exit(0);
 		}
-		if (res == -3) {
+		if (res == DEPOT_PERM_DENIED) {
 			// permission denied when trying to read
 			// the depot
 			fprintf(stderr, "Permission denied when trying to read the database.\n");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100916/c049fc2e/attachment.html>


More information about the darwinbuild-changes mailing list