[darwinbuild-changes] [759] branches/PR-7593824/darwinup
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 10 14:15:23 PST 2010
Revision: 759
http://trac.macosforge.org/projects/darwinbuild/changeset/759
Author: wsiegrist at apple.com
Date: 2010-03-10 14:15:23 -0800 (Wed, 10 Mar 2010)
Log Message:
-----------
Support arbitrary optional archive specifier arguments to list subcommand
Modified Paths:
--------------
branches/PR-7593824/darwinup/Depot.cpp
branches/PR-7593824/darwinup/Depot.h
branches/PR-7593824/darwinup/main.cpp
Modified: branches/PR-7593824/darwinup/Depot.cpp
===================================================================
--- branches/PR-7593824/darwinup/Depot.cpp 2010-03-10 22:15:01 UTC (rev 758)
+++ branches/PR-7593824/darwinup/Depot.cpp 2010-03-10 22:15:23 UTC (rev 759)
@@ -986,9 +986,42 @@
}
int Depot::list() {
+ return this->list(0, NULL);
+}
+
+int Depot::list(int count, char** args) {
int res = 0;
+
this->archive_header();
- if (res == 0) res = this->iterate_archives(&Depot::list_archive, stdout);
+
+ // handle the default case of "all"
+ if (count == 0) return this->iterate_archives(&Depot::list_archive, stdout);
+
+ Archive** list;
+ Archive* archive;
+ uint32_t archcnt;
+ for (int i = 0; res == 0 && i < count; i++) {
+ list = NULL;
+ archive = NULL;
+ archcnt = 0;
+ // check for special keywords
+ if (strncasecmp(args[i], "all", 3) == 0) {
+ list = this->get_all_archives(&archcnt);
+ } else if (strncasecmp(args[i], "superseded", 10) == 0) {
+ list = this->get_superseded_archives(&archcnt);
+ }
+ if (archcnt) {
+ // loop over special keyword results
+ for (uint32_t j = 0; res == 0 && j < archcnt; j++) {
+ res = this->list_archive(list[j], stdout);
+ }
+ } else {
+ // arg is a single-archive specifier
+ archive = this->get_archive(args[i]);
+ if (archive) res = this->list_archive(archive, stdout);
+ }
+ }
+
return res;
}
Modified: branches/PR-7593824/darwinup/Depot.h
===================================================================
--- branches/PR-7593824/darwinup/Depot.h 2010-03-10 22:15:01 UTC (rev 758)
+++ branches/PR-7593824/darwinup/Depot.h 2010-03-10 22:15:23 UTC (rev 759)
@@ -86,6 +86,7 @@
static int dump_archive(Archive* archive, void* context);
int list();
+ int list(int count, char** args);
static int list_archive(Archive* archive, void* context);
int install(const char* path);
Modified: branches/PR-7593824/darwinup/main.cpp
===================================================================
--- branches/PR-7593824/darwinup/main.cpp 2010-03-10 22:15:01 UTC (rev 758)
+++ branches/PR-7593824/darwinup/main.cpp 2010-03-10 22:15:23 UTC (rev 759)
@@ -55,7 +55,7 @@
fprintf(stderr, "commands: \n");
fprintf(stderr, " files <archive> \n");
fprintf(stderr, " install <path> \n");
- fprintf(stderr, " list \n");
+ fprintf(stderr, " list [archive] \n");
fprintf(stderr, " uninstall <archive> \n");
fprintf(stderr, " upgrade <path> \n");
fprintf(stderr, " verify <archive> \n");
@@ -71,7 +71,7 @@
fprintf(stderr, " tar, tar.gz, tar.bz2 \n");
fprintf(stderr, " xar, zip \n");
fprintf(stderr, " \n");
- fprintf(stderr, "<archive> is one of: \n");
+ fprintf(stderr, "archive is one of: \n");
fprintf(stderr, " <serial> the Serial number \n");
fprintf(stderr, " <uuid> the UUID \n");
fprintf(stderr, " <name> the last root installed with that name \n");
@@ -134,54 +134,58 @@
Depot* depot = new Depot(path);
- // commands with no arguments
- if (argc == 1) {
- if (strcmp(argv[0], "list") == 0) {
- res = depot->initialize(false);
- if (res == -2) {
- fprintf(stdout, "Nothing has been installed yet.\n");
- exit(0);
- }
- if (res == 0) depot->list();
- } else if (strcmp(argv[0], "dump") == 0) {
+ // list handles args optional and in special ways
+ if (strcmp(argv[0], "list") == 0) {
+ res = depot->initialize(false);
+ if (res == -2) {
+ // we are not asking to write,
+ // but no depot exists yet either,
+ // so print the apparent truth
+ fprintf(stdout, "Nothing has been installed yet.\n");
+ exit(0);
+ }
+ if (res == 0) depot->list(argc-1, (char**)(argv+1));
+ } else if (argc == 1) {
+ // other commands which take no arguments
+ if (strcmp(argv[0], "dump") == 0) {
if (depot->initialize(false)) exit(11);
depot->dump();
} else {
usage(progname);
}
- }
-
- // loop over arguments
- for (int i = 1; i < argc; i++) {
- if (strcmp(argv[0], "install") == 0) {
- if (i==1 && depot->initialize(true)) exit(13);
- res = depot->install(argv[i]);
- if (res == 0) res = update_dyld_shared_cache(path);
- } else if (strcmp(argv[0], "upgrade") == 0) {
- if (i==1 && depot->initialize(true)) exit(14);
- // find most recent matching archive by name
- Archive* old = depot->get_archive(basename(argv[i]));
- if (!old) {
- fprintf(stderr, "Error: unable to find a matching root to upgrade.\n");
- res = 5;
+ } else {
+ // loop over arguments
+ for (int i = 1; i < argc; i++) {
+ if (strcmp(argv[0], "install") == 0) {
+ if (i==1 && depot->initialize(true)) exit(13);
+ res = depot->install(argv[i]);
+ if (res == 0) res = update_dyld_shared_cache(path);
+ } else if (strcmp(argv[0], "upgrade") == 0) {
+ if (i==1 && depot->initialize(true)) exit(14);
+ // find most recent matching archive by name
+ Archive* old = depot->get_archive(basename(argv[i]));
+ if (!old) {
+ fprintf(stderr, "Error: unable to find a matching root to upgrade.\n");
+ res = 5;
+ }
+ // install new archive
+ if (res == 0) res = depot->install(argv[i]);
+ // uninstall old archive
+ if (res == 0) res = depot->uninstall(old);
+ if (res == 0) res = update_dyld_shared_cache(path);
+ } else if (strcmp(argv[0], "files") == 0) {
+ if (i==1 && depot->initialize(false)) exit(12);
+ res = depot->process_archive(argv[0], argv[i]);
+ } else if (strcmp(argv[0], "uninstall") == 0) {
+ if (i==1 && depot->initialize(true)) exit(15);
+ res = depot->process_archive(argv[0], argv[i]);
+ if (res == 0) res = update_dyld_shared_cache(path);
+ } else if (strcmp(argv[0], "verify") == 0) {
+ if (i==1 && depot->initialize(true)) exit(16);
+ res = depot->process_archive(argv[0], argv[i]);
+ } else {
+ usage(progname);
}
- // install new archive
- if (res == 0) res = depot->install(argv[i]);
- // uninstall old archive
- if (res == 0) res = depot->uninstall(old);
- if (res == 0) res = update_dyld_shared_cache(path);
- } else if (strcmp(argv[0], "files") == 0) {
- if (i==1 && depot->initialize(false)) exit(12);
- res = depot->process_archive(argv[0], argv[i]);
- } else if (strcmp(argv[0], "uninstall") == 0) {
- if (i==1 && depot->initialize(true)) exit(15);
- res = depot->process_archive(argv[0], argv[i]);
- if (res == 0) res = update_dyld_shared_cache(path);
- } else if (strcmp(argv[0], "verify") == 0) {
- if (i==1 && depot->initialize(true)) exit(16);
- res = depot->process_archive(argv[0], argv[i]);
- } else {
- usage(progname);
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100310/e2942b7e/attachment-0001.html>
More information about the darwinbuild-changes
mailing list