diff -r 5549419824b4 -r 3cde352d3270 src/main.c --- a/src/main.c Wed Jul 08 22:14:16 2009 +0100 +++ b/src/main.c Mon Sep 28 17:36:02 2009 +0100 @@ -42,7 +42,6 @@ static const char system_repo_filename[] = "system.rzdb"; static const char next_repo_filename[] = "system-next.rzdb"; static const char rawhide_repo_filename[] = "rawhide.rzdb"; -static const char updated_repo_filename[] = "system-updated.rzdb"; static const char *install_root = ""; static const char *repo_filename = system_repo_filename; static const char *yum_url; @@ -549,50 +548,6 @@ } static int -command_update(int argc, const char *argv[]) -{ - struct razor_set *set, *upstream; - struct razor_transaction *trans; - int i, errors; - - set = razor_root_open_read_only(install_root); - if (set == NULL) - return 1; - - upstream = razor_set_open(rawhide_repo_filename); - if (upstream == NULL) - return 1; - - trans = razor_transaction_create(set, upstream); - if (argc == 0) - razor_transaction_update_all(trans); - for (i = 0; i < argc; i++) { - if (mark_packages_for_update(trans, set, argv[i]) == 0) { - fprintf(stderr, "no match for %s\n", argv[i]); - razor_transaction_destroy(trans); - return 1; - } - } - - razor_transaction_resolve(trans); - errors = razor_transaction_describe(trans); - if (errors) { - fprintf(stderr, "unresolved dependencies\n"); - razor_transaction_destroy(trans); - return 1; - } - - set = razor_transaction_commit(trans); - razor_set_write(set, updated_repo_filename, RAZOR_SECTION_ALL); - razor_transaction_destroy(trans); - razor_set_destroy(set); - razor_set_destroy(upstream); - printf("wrote system-updated.rzdb\n"); - - return 0; -} - -static int command_remove(int argc, const char *argv[]) { struct razor_root *root; @@ -659,7 +614,7 @@ struct razor_set *set, *updated; set = razor_root_open_read_only(install_root); - updated = razor_set_open(updated_repo_filename); + updated = razor_set_open(rawhide_repo_filename); if (set == NULL || updated == NULL) return 1; @@ -756,19 +711,17 @@ { struct razor_install_iterator *ii; struct razor_package *package; - struct razor_set *set; enum razor_install_action action; const char *name, *version, *arch; char file[PATH_MAX], url[256]; int errors = 0, count; ii = razor_set_create_install_iterator(system, next); - while (razor_install_iterator_next(ii, &set, &package, - &action, &count)) { + while (razor_install_iterator_next(ii, &package, &action, &count)) { if (action == RAZOR_INSTALL_ACTION_REMOVE) continue; - razor_package_get_details(set, package, + razor_package_get_details(next, package, RAZOR_DETAIL_NAME, &name, RAZOR_DETAIL_VERSION, &version, RAZOR_DETAIL_ARCH, &arch, @@ -920,19 +873,18 @@ { struct razor_install_iterator *ii; struct razor_package *package; - struct razor_set *set; enum razor_install_action action; int retval = 0, count; ii = razor_set_create_install_iterator(system, next); - while (!retval && razor_install_iterator_next(ii, &set, &package, + while (!retval && razor_install_iterator_next(ii, &package, &action, &count)) { if (action == RAZOR_INSTALL_ACTION_ADD) - retval = install_package(trans, set, package, + retval = install_package(trans, next, package, relocations); else if (action == RAZOR_INSTALL_ACTION_REMOVE) - retval = razor_package_remove(set, package, - install_root, 0); + retval = razor_package_remove(system, next, package, + install_root, count); } razor_install_iterator_destroy(ii); @@ -940,7 +892,7 @@ } static int -command_install(int argc, const char *argv[]) +command_install_or_update(int argc, const char *argv[], int do_update) { struct razor_root *root; struct razor_relocations *relocations=NULL; @@ -960,7 +912,8 @@ i++; if (i >= argc || strchr(argv[i], '=') == NULL) { fprintf(stderr, - "Usage: razor install [OPTION...] RPM\n"); + "Usage: razor %s [OPTION...] RPM\n", + do_update ? "update" : "install"); fprintf(stderr, "Options:\n"); fprintf(stderr, " [--no-dependencies]\n"); fprintf(stderr, @@ -983,10 +936,9 @@ system = razor_root_get_system_set(root); upstream = razor_set_open(rawhide_repo_filename); if (upstream == NULL) { - fprintf(stderr, "couldn't open rawhide repo\n"); razor_root_close(root); return 1; - } + } if (relocations) { set = relocate_packages(upstream, relocations); @@ -996,10 +948,13 @@ trans = razor_transaction_create(system, upstream); + if (i == argc && do_update) + razor_transaction_update_all(trans); for (; i < argc; i++) { if (mark_packages_for_update(trans, upstream, argv[i]) == 0) { fprintf(stderr, "no package matched %s\n", argv[i]); razor_transaction_destroy(trans); + razor_set_destroy(upstream); razor_root_close(root); return 1; } @@ -1009,22 +964,26 @@ razor_transaction_resolve(trans); if (razor_transaction_describe(trans) > 0) { razor_transaction_destroy(trans); + razor_set_destroy(upstream); razor_root_close(root); return 1; } } - next = razor_transaction_commit(trans); - if (mkdir("rpms", 0777) && errno != EEXIST) { fprintf(stderr, "failed to create rpms directory.\n"); razor_transaction_destroy(trans); + razor_set_destroy(upstream); razor_root_close(root); return 1; } + next = razor_transaction_commit(trans); + if (download_packages(system, next) < 0) { + razor_set_destroy(next); razor_transaction_destroy(trans); + razor_set_destroy(upstream); razor_root_close(root); return 1; } @@ -1043,6 +1002,18 @@ } static int +command_update(int argc, const char *argv[]) +{ + return command_install_or_update(argc, argv, 1); +} + +static int +command_install(int argc, const char *argv[]) +{ + return command_install_or_update(argc, argv, 0); +} + +static int command_init(int argc, const char *argv[]) { return razor_root_create(install_root);