summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2008-06-29 22:38:57 -0400
committerKristian Høgsberg <krh@redhat.com>2008-06-30 13:28:59 -0400
commit27e3b5098d6c01d978cb5d530ea98f5f4069b25d (patch)
treeeb609d3c262f03518ff570dbc311dc3261941019 /src
parent2d4487425bcbca6b4f0f86aaa8e2f276ec54c0a5 (diff)
Get rid of razor_set_get_package().
This was always a silly little helper function, not general enough for real world applications. Use an iterator to search through the set to find the package of interest.
Diffstat (limited to 'src')
-rw-r--r--src/main.c52
-rw-r--r--src/rpm.c2
-rw-r--r--src/test-driver.c26
3 files changed, 53 insertions, 27 deletions
diff --git a/src/main.c b/src/main.c
index f680d1f..98b4ff1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -119,26 +119,15 @@ command_list(int argc, const char *argv[])
return 0;
}
-static int
-list_properties(const char *package_name, uint32_t type)
+static void
+list_package_properties(struct razor_set *set,
+ struct razor_package *package, uint32_t type)
{
- struct razor_set *set;
- struct razor_property *property;
- struct razor_package *package;
struct razor_property_iterator *pi;
+ struct razor_property *property;
const char *name, *version;
uint32_t flags;
- set = razor_set_open(repo_filename);
- if (package_name) {
- package = razor_set_get_package(set, package_name);
- if (!package) {
- fprintf(stderr, "no package named \"%s\"\n", package_name);
- return 1;
- }
- } else
- package = NULL;
-
pi = razor_property_iterator_create(set, package);
while (razor_property_iterator_next(pi, &property,
&name, &flags, &version)) {
@@ -165,7 +154,22 @@ list_properties(const char *package_name, uint32_t type)
printf("\n");
}
razor_property_iterator_destroy(pi);
+}
+static int
+list_properties(int argc, const char *argv[], uint32_t type)
+{
+ struct razor_set *set;
+ struct razor_package *package;
+ struct razor_package_iterator *pi;
+ const char *name, *version, *arch;
+
+ set = razor_set_open(repo_filename);
+ pi = create_iterator_from_argv(set, argc, argv);
+ while (razor_package_iterator_next(pi, &package,
+ &name, &version, &arch))
+ list_package_properties(set, package, type);
+ razor_package_iterator_destroy(pi);
razor_set_destroy(set);
return 0;
@@ -174,25 +178,25 @@ list_properties(const char *package_name, uint32_t type)
static int
command_list_requires(int argc, const char *argv[])
{
- return list_properties(argv[0], RAZOR_PROPERTY_REQUIRES);
+ return list_properties(argc, argv, RAZOR_PROPERTY_REQUIRES);
}
static int
command_list_provides(int argc, const char *argv[])
{
- return list_properties(argv[0], RAZOR_PROPERTY_PROVIDES);
+ return list_properties(argc, argv, RAZOR_PROPERTY_PROVIDES);
}
static int
command_list_obsoletes(int argc, const char *argv[])
{
- return list_properties(argv[0], RAZOR_PROPERTY_OBSOLETES);
+ return list_properties(argc, argv, RAZOR_PROPERTY_OBSOLETES);
}
static int
command_list_conflicts(int argc, const char *argv[])
{
- return list_properties(argv[0], RAZOR_PROPERTY_CONFLICTS);
+ return list_properties(argc, argv, RAZOR_PROPERTY_CONFLICTS);
}
static int
@@ -237,6 +241,9 @@ static int
command_list_package_files(int argc, const char *argv[])
{
struct razor_set *set;
+ struct razor_package_iterator *pi;
+ struct razor_package *package;
+ const char *name, *version, *arch;
set = razor_set_open(repo_filename);
if (set == NULL)
@@ -244,7 +251,12 @@ command_list_package_files(int argc, const char *argv[])
if (razor_set_open_files(set, "system-files.repo"))
return 1;
- razor_set_list_package_files(set, argv[0]);
+ pi = create_iterator_from_argv(set, argc, argv);
+ while (razor_package_iterator_next(pi, &package,
+ &name, &version, &arch))
+ razor_set_list_package_files(set, package);
+ razor_package_iterator_destroy(pi);
+
razor_set_destroy(set);
return 0;
diff --git a/src/rpm.c b/src/rpm.c
index f752aa9..bd31434 100644
--- a/src/rpm.c
+++ b/src/rpm.c
@@ -512,7 +512,7 @@ command_query(int argc, const char *argv[])
if (option_changelog)
print_package_changelog(set, package);
if (option_list)
- razor_set_list_package_files(set, name);
+ razor_set_list_package_files(set, package);
if (option_conflicts + option_obsoletes +
option_requires + option_provides +
diff --git a/src/test-driver.c b/src/test-driver.c
index 5223118..bd7aa17 100644
--- a/src/test-driver.c
+++ b/src/test-driver.c
@@ -285,6 +285,23 @@ start_transaction(struct test_context *ctx, const char **atts)
ctx->n_remove_pkgs = 0;
}
+static struct razor_package *
+get_package(struct razor_set *set, const char *package)
+{
+ struct razor_package_iterator *pi;
+ struct razor_package *p;
+ const char *name, *version, *arch;
+
+ pi = razor_package_iterator_create(set);
+ while (razor_package_iterator_next(pi, &p, &name, &version, &arch)) {
+ if (strcmp(package, name) == 0)
+ break;
+ }
+ razor_package_iterator_destroy(pi);
+
+ return p;
+}
+
static void
end_transaction(struct test_context *ctx)
{
@@ -293,16 +310,13 @@ end_transaction(struct test_context *ctx)
ctx->trans = razor_transaction_create(ctx->system_set, ctx->repo_set);
for (i = 0; i < ctx->n_install_pkgs; i++) {
- pkg = razor_set_get_package(ctx->repo_set,
- ctx->install_pkgs[i]);
+ pkg = get_package(ctx->repo_set, ctx->install_pkgs[i]);
razor_transaction_install_package(ctx->trans, pkg);
}
for (i = 0; i < ctx->n_remove_pkgs; i++) {
- pkg = razor_set_get_package(ctx->system_set,
- ctx->remove_pkgs[i]);
+ pkg = get_package(ctx->system_set, ctx->remove_pkgs[i]);
if (!pkg)
- pkg = razor_set_get_package(ctx->repo_set,
- ctx->remove_pkgs[i]);
+ pkg = get_package(ctx->repo_set, ctx->remove_pkgs[i]);
razor_transaction_remove_package(ctx->trans, pkg);
}