[darwinbuild-changes] [834] branches/PR-7872907
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jun 10 10:38:02 PDT 2010
Revision: 834
http://trac.macosforge.org/projects/darwinbuild/changeset/834
Author: wsiegrist at apple.com
Date: 2010-06-10 10:38:00 -0700 (Thu, 10 Jun 2010)
Log Message:
-----------
Add rename command, including tests.
Modified Paths:
--------------
branches/PR-7872907/darwinup/Depot.cpp
branches/PR-7872907/darwinup/Depot.h
branches/PR-7872907/darwinup/main.cpp
branches/PR-7872907/testing/darwinup/run-tests.sh
Modified: branches/PR-7872907/darwinup/Depot.cpp
===================================================================
--- branches/PR-7872907/darwinup/Depot.cpp 2010-06-10 17:36:54 UTC (rev 833)
+++ branches/PR-7872907/darwinup/Depot.cpp 2010-06-10 17:38:00 UTC (rev 834)
@@ -1371,26 +1371,26 @@
}
// perform a command on an archive specification
-int Depot::process_archive(const char* command, const char* arg) {
+int Depot::process_archive(const char* command, const char* archspec) {
extern uint32_t verbosity;
int res = 0;
uint32_t count = 0;
Archive** list = NULL;
- if (strncasecmp(arg, "all", 3) == 0) {
+ if (strncasecmp(archspec, "all", 3) == 0) {
list = this->get_all_archives(&count);
- } else if (strncasecmp(arg, "superseded", 10) == 0) {
+ } else if (strncasecmp(archspec, "superseded", 10) == 0) {
list = this->get_superseded_archives(&count);
} else {
// make a list of 1 Archive
list = (Archive**)malloc(sizeof(Archive*));
- list[0] = this->get_archive(arg);
+ list[0] = this->get_archive(archspec);
count = 1;
}
for (size_t i = 0; i < count; i++) {
if (!list[i]) {
- fprintf(stdout, "Archive not found: %s\n", arg);
+ fprintf(stdout, "Archive not found: %s\n", archspec);
return -1;
}
if (verbosity & VERBOSE_DEBUG) {
@@ -1404,3 +1404,48 @@
free(list);
return res;
}
+
+int Depot::rename_archive(const char* archspec, const char* name) {
+ extern uint32_t verbosity;
+ int res = 0;
+ char uuid[37];
+
+ if (strncasecmp(archspec, "all", 3) == 0 ||
+ strncasecmp(archspec, "superseded", 10) == 0) {
+ fprintf(stderr, "Error: keywords 'all' and 'superseded' cannot be used with the"
+ " rename command.\n");
+ return -2;
+ }
+
+ Archive* archive = this->get_archive(archspec);
+ if (!archive) {
+ fprintf(stdout, "Archive not found: %s\n", archspec);
+ return -1;
+ }
+ if (verbosity & VERBOSE_DEBUG) {
+ uuid_unparse_upper(archive->uuid(), uuid);
+ fprintf(stdout, "Found archive: %s\n", uuid);
+ }
+ if (!name || strlen(name) == 0) {
+ fprintf(stderr, "Error: invalid name: '%s'\n", name);
+ return -3;
+ }
+
+ free(archive->m_name);
+ archive->m_name = strdup(name);
+
+ res = m_db->update_archive(archive->serial(),
+ archive->uuid(),
+ archive->name(),
+ archive->date_installed(),
+ 1,
+ archive->info(),
+ archive->build());
+
+ if (res == 0 && (verbosity & VERBOSE_DEBUG)) {
+ fprintf(stdout, "Renamed archive %s to '%s'.\n", uuid, archive->name());
+ }
+
+ delete archive;
+ return res;
+}
Modified: branches/PR-7872907/darwinup/Depot.h
===================================================================
--- branches/PR-7872907/darwinup/Depot.h 2010-06-10 17:36:54 UTC (rev 833)
+++ branches/PR-7872907/darwinup/Depot.h 2010-06-10 17:38:00 UTC (rev 834)
@@ -110,8 +110,10 @@
// processes an archive according to command
// arg is an archive identifier, such as serial or uuid
int dispatch_command(Archive* archive, const char* command);
- int process_archive(const char* command, const char* arg);
+ int process_archive(const char* command, const char* archspec);
+ int rename_archive(const char* archspec, const char* name);
+
// test if the depot is currently locked
int is_locked();
Modified: branches/PR-7872907/darwinup/main.cpp
===================================================================
--- branches/PR-7872907/darwinup/main.cpp 2010-06-10 17:36:54 UTC (rev 833)
+++ branches/PR-7872907/darwinup/main.cpp 2010-06-10 17:38:00 UTC (rev 834)
@@ -61,6 +61,7 @@
fprintf(stderr, " files <archive> \n");
fprintf(stderr, " install <path> \n");
fprintf(stderr, " list [archive] \n");
+ fprintf(stderr, " rename <archive> <name> \n");
fprintf(stderr, " uninstall <archive> \n");
fprintf(stderr, " upgrade <path> \n");
fprintf(stderr, " verify <archive> \n");
@@ -149,7 +150,7 @@
}
}
argc -= optind;
- argv += optind;
+ argv += optind;
if (argc == 0) usage(progname);
int res = 0;
@@ -191,11 +192,12 @@
if (depot->initialize(false)) exit(11);
depot->dump();
} else {
+ fprintf(stderr, "Error: unknown command: '%s' \n", argv[0]);
usage(progname);
}
} else {
// loop over arguments
- for (int i = 1; i < argc; i++) {
+ for (int i = 1; i < argc && res == 0; i++) {
if (strcmp(argv[0], "install") == 0) {
if (i==1 && depot->initialize(true)) exit(13);
res = depot->install(argv[i]);
@@ -220,7 +222,18 @@
} else if (strcmp(argv[0], "verify") == 0) {
if (i==1 && depot->initialize(true)) exit(16);
res = depot->process_archive(argv[0], argv[i]);
+ } else if (strcmp(argv[0], "rename") == 0) {
+ if (i==1 && depot->initialize(true)) exit(17);
+ if ((i+1) >= argc) {
+ fprintf(stderr,
+ "Error: rename command for '%s' takes 2 arguments.\n",
+ argv[i]);
+ exit(18);
+ }
+ res = depot->rename_archive(argv[i], argv[i+1]);
+ i++;
} else {
+ fprintf(stderr, "Error: unknown command: '%s' \n", argv[0]);
usage(progname);
}
}
Modified: branches/PR-7872907/testing/darwinup/run-tests.sh
===================================================================
--- branches/PR-7872907/testing/darwinup/run-tests.sh 2010-06-10 17:36:54 UTC (rev 833)
+++ branches/PR-7872907/testing/darwinup/run-tests.sh 2010-06-10 17:38:00 UTC (rev 834)
@@ -272,6 +272,26 @@
$DIFF $ORIG $DEST 2>&1
+echo "========== TEST: Archive Rename ============="
+$DARWINUP install $PREFIX/root2
+$DARWINUP install $PREFIX/root
+$DARWINUP install $PREFIX/root6
+$DARWINUP rename root "RENAME1"
+C=$($DARWINUP list | grep "RENAME1" | wc -l | xargs)
+test "$C" == "1"
+$DARWINUP rename oldest "RENAME2"
+C=$($DARWINUP list | grep "RENAME2" | wc -l | xargs)
+test "$C" == "1"
+$DARWINUP uninstall "RENAME1"
+C=$($DARWINUP list | grep "RENAME1" | wc -l | xargs)
+test "$C" == "0"
+C=$($DARWINUP files "RENAME2" | wc -l | xargs)
+test "$C" == "17"
+C=$($DARWINUP verify "RENAME2" | wc -l | xargs)
+test "$C" == "17"
+
+
+
#
# The following are expected failures
#
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100610/7a2bda60/attachment-0001.html>
More information about the darwinbuild-changes
mailing list