1.1 --- a/main.c Mon Apr 07 21:32:19 2008 -0400
1.2 +++ b/main.c Mon Apr 07 23:52:14 2008 -0400
1.3 @@ -356,17 +356,71 @@
1.4 }
1.5
1.6 static int
1.7 +mark_packages_for_update(struct razor_transaction *trans,
1.8 + struct razor_set *set, const char *pattern)
1.9 +{
1.10 + struct razor_package_iterator *pi;
1.11 + struct razor_package *package;
1.12 + const char *name, *version, *arch;
1.13 + int matches = 0;
1.14 +
1.15 + pi = razor_package_iterator_create(set);
1.16 + while (razor_package_iterator_next(pi, &package,
1.17 + &name, &version, &arch)) {
1.18 + if (pattern && fnmatch(pattern, name, 0) == 0) {
1.19 + razor_transaction_install_package(trans, package);
1.20 + matches++;
1.21 + }
1.22 + }
1.23 + razor_package_iterator_destroy(pi);
1.24 +
1.25 + return matches;
1.26 +}
1.27 +
1.28 +static int
1.29 +mark_packages_for_removal(struct razor_transaction *trans,
1.30 + struct razor_set *set, const char *pattern)
1.31 +{
1.32 + struct razor_package_iterator *pi;
1.33 + struct razor_package *package;
1.34 + const char *name, *version, *arch;
1.35 + int matches = 0;
1.36 +
1.37 + pi = razor_package_iterator_create(set);
1.38 + while (razor_package_iterator_next(pi, &package,
1.39 + &name, &version, &arch)) {
1.40 + if (pattern && fnmatch(pattern, name, 0) == 0) {
1.41 + razor_transaction_remove_package(trans, package);
1.42 + matches++;
1.43 + }
1.44 + }
1.45 + razor_package_iterator_destroy(pi);
1.46 +
1.47 + return matches;
1.48 +}
1.49 +
1.50 +static int
1.51 command_update(int argc, const char *argv[])
1.52 {
1.53 struct razor_set *set, *upstream;
1.54 struct razor_transaction *trans;
1.55 - int errors;
1.56 + int i, errors;
1.57
1.58 set = razor_set_open(repo_filename);
1.59 upstream = razor_set_open(rawhide_repo_filename);
1.60 if (set == NULL || upstream == NULL)
1.61 return 1;
1.62 - trans = razor_transaction_create(set, upstream, argc, argv, 0, NULL);
1.63 +
1.64 + trans = razor_transaction_create(set, upstream);
1.65 + if (argc == 0)
1.66 + razor_transaction_update_all(trans);
1.67 + for (i = 0; i < argc; i++) {
1.68 + if (mark_packages_for_update(trans, upstream, argv[i]) == 0) {
1.69 + fprintf(stderr, "no match for %s\n", argv[i]);
1.70 + return 1;
1.71 + }
1.72 + }
1.73 +
1.74 errors = razor_transaction_describe(trans);
1.75 if (errors)
1.76 return 1;
1.77 @@ -385,12 +439,20 @@
1.78 {
1.79 struct razor_set *set;
1.80 struct razor_transaction *trans;
1.81 - int errors;
1.82 + int i, errors;
1.83
1.84 set = razor_set_open(repo_filename);
1.85 if (set == NULL)
1.86 return 1;
1.87 - trans = razor_transaction_create(set, NULL, 0, NULL, argc, argv);
1.88 +
1.89 + trans = razor_transaction_create(set, NULL);
1.90 + for (i = 0; i < argc; i++) {
1.91 + if (mark_packages_for_removal(trans, set, argv[i]) == 0) {
1.92 + fprintf(stderr, "no match for %s\n", argv[i]);
1.93 + return 1;
1.94 + }
1.95 + }
1.96 +
1.97 errors = razor_transaction_describe(trans);
1.98 if (errors)
1.99 return 1;
1.100 @@ -564,7 +626,7 @@
1.101 struct razor_set *system, *upstream, *next;
1.102 struct razor_transaction *trans;
1.103 char path[PATH_MAX], new_path[PATH_MAX];
1.104 - int errors, fd;
1.105 + int i, errors, fd;
1.106
1.107 /* Create the new next repo file up front to ensure exclusive
1.108 * access. */
1.109 @@ -590,8 +652,15 @@
1.110 unlink(new_path);
1.111 return 1;
1.112 }
1.113 - trans = razor_transaction_create(system, upstream,
1.114 - argc, argv, 0, NULL);
1.115 + trans = razor_transaction_create(system, upstream);
1.116 + for (i = 0; i < argc; i++) {
1.117 + if (mark_packages_for_update(trans, upstream, argv[i]) == 0) {
1.118 + fprintf(stderr, "no package matched %s\n", argv[i]);
1.119 + unlink(new_path);
1.120 + return 1;
1.121 + }
1.122 + }
1.123 +
1.124 errors = razor_transaction_describe(trans);
1.125 if (errors) {
1.126 unlink(new_path);