Fix a few warnings.
13 static const char *repo_filename = "system.repo";
14 static const char *rawhide_repo_filename = "rawhide.repo";
15 static const char *updated_repo_filename = "system-updated.repo";
18 command_list(int argc, const char *argv[])
20 struct razor_set *set;
21 struct razor_package_iterator *pi;
22 struct razor_package *package;
23 const char *pattern = argv[0], *name, *version;
25 set = razor_set_open(repo_filename);
26 pi = razor_package_iterator_create(set);
27 while (razor_package_iterator_next(pi, &package, &name, &version)) {
28 if (pattern && fnmatch(pattern, name, 0) != 0)
31 printf("%s-%s\n", name, version);
33 razor_package_iterator_destroy(pi);
34 razor_set_destroy(set);
40 list_properties(const char *package_name,
41 enum razor_property_type required_type)
43 struct razor_set *set;
44 struct razor_property *property;
45 struct razor_package *package;
46 struct razor_property_iterator *pi;
47 const char *name, *version;
48 enum razor_property_type type;
50 set = razor_set_open(repo_filename);
52 package = razor_set_get_package(set, package_name);
56 pi = razor_property_iterator_create(set, package);
57 while (razor_property_iterator_next(pi, &property,
58 &name, &version, &type)) {
59 if (type != required_type)
61 if (version[0] == '\0')
64 printf("%s-%s\n", name, version);
66 razor_property_iterator_destroy(pi);
68 razor_set_destroy(set);
74 command_list_requires(int argc, const char *argv[])
76 return list_properties(argv[0], RAZOR_PROPERTY_REQUIRES);
80 command_list_provides(int argc, const char *argv[])
82 return list_properties(argv[0], RAZOR_PROPERTY_PROVIDES);
86 command_list_obsoletes(int argc, const char *argv[])
88 return list_properties(argv[0], RAZOR_PROPERTY_OBSOLETES);
92 command_list_conflicts(int argc, const char *argv[])
94 return list_properties(argv[0], RAZOR_PROPERTY_CONFLICTS);
98 command_list_files(int argc, const char *argv[])
100 struct razor_set *set;
102 set = razor_set_open(repo_filename);
105 razor_set_list_files(set, argv[0]);
106 razor_set_destroy(set);
112 command_list_file_packages(int argc, const char *argv[])
114 struct razor_set *set;
116 set = razor_set_open(repo_filename);
119 razor_set_list_file_packages(set, argv[0]);
120 razor_set_destroy(set);
126 command_list_package_files(int argc, const char *argv[])
128 struct razor_set *set;
130 set = razor_set_open(repo_filename);
133 razor_set_list_package_files(set, argv[0]);
134 razor_set_destroy(set);
140 command_what_requires(int argc, const char *argv[])
142 struct razor_set *set;
144 set = razor_set_open(repo_filename);
145 razor_set_list_property_packages(set, argv[0], argv[1],
146 RAZOR_PROPERTY_REQUIRES);
147 razor_set_destroy(set);
153 command_what_provides(int argc, const char *argv[])
155 struct razor_set *set;
157 set = razor_set_open(repo_filename);
158 razor_set_list_property_packages(set, argv[0], argv[1],
159 RAZOR_PROPERTY_PROVIDES);
160 razor_set_destroy(set);
166 show_progress(void *clientp,
167 double dltotal, double dlnow, double ultotal, double ulnow)
169 const char *file = clientp;
171 if (!dlnow < dltotal)
172 fprintf(stderr, "\rdownloading %s, %dkB/%dkB",
173 file, (int) dlnow / 1024, (int) dltotal / 1024);
175 fprintf(stderr, "\n");
181 download_if_missing(CURL *curl, const char *url, const char *file)
189 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
190 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
191 curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, show_progress);
192 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, file);
194 if (stat(file, &buf) < 0) {
195 fp = fopen(file, "w");
196 snprintf(buffer, sizeof buffer, "%s/%s", url, file);
197 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
198 curl_easy_setopt(curl, CURLOPT_URL, buffer);
199 res = curl_easy_perform(curl);
201 if (res != CURLE_OK) {
202 fprintf(stderr, "curl error: %s\n", error);
211 #define REPO_URL "http://download.fedora.redhat.com" \
212 "/pub/fedora/linux/development/i386/os/repodata"
215 command_import_yum(int argc, const char *argv[])
217 struct razor_set *set;
220 curl = curl_easy_init();
224 if (download_if_missing(curl, REPO_URL, "primary.xml.gz") < 0)
226 if (download_if_missing(curl, REPO_URL, "filelists.xml.gz") < 0)
228 curl_easy_cleanup(curl);
230 set = razor_set_create_from_yum();
233 razor_set_write(set, rawhide_repo_filename);
234 razor_set_destroy(set);
235 printf("wrote %s\n", rawhide_repo_filename);
241 command_import_rpmdb(int argc, const char *argv[])
243 struct razor_set *set;
245 set = razor_set_create_from_rpmdb();
248 razor_set_write(set, repo_filename);
249 razor_set_destroy(set);
250 printf("wrote %s\n", repo_filename);
256 command_validate(int argc, const char *argv[])
258 struct razor_set *set;
260 set = razor_set_open(repo_filename);
263 razor_set_list_unsatisfied(set);
264 razor_set_destroy(set);
270 command_update(int argc, const char *argv[])
272 struct razor_set *set, *upstream;
274 set = razor_set_open(repo_filename);
275 upstream = razor_set_open(rawhide_repo_filename);
276 if (set == NULL || upstream == NULL)
278 set = razor_set_update(set, upstream, argc, argv);
279 razor_set_write(set, updated_repo_filename);
280 razor_set_destroy(set);
281 razor_set_destroy(upstream);
282 printf("wrote system-updated.repo\n");
288 print_diff(const char *name,
289 const char *old_version, const char *new_version, void *data)
292 printf("removing %s %s\n", name, old_version);
294 printf("install %s %s\n", name, new_version);
298 command_diff(int argc, const char *argv[])
300 struct razor_set *set, *updated;
302 set = razor_set_open(repo_filename);
303 updated = razor_set_open(updated_repo_filename);
304 if (set == NULL || updated == NULL)
307 razor_set_diff(set, updated, print_diff, NULL);
309 razor_set_destroy(set);
310 razor_set_destroy(updated);
316 command_import_rpms(int argc, const char *argv[])
320 struct razor_importer *importer;
321 struct razor_set *set;
322 struct razor_rpm *rpm;
325 const char *dirname = argv[0];
327 if (dirname == NULL) {
328 fprintf(stderr, "usage: razor import-rpms DIR\n");
332 dir = opendir(dirname);
334 fprintf(stderr, "couldn't read dir %s\n", dirname);
338 importer = razor_importer_new();
340 while (de = readdir(dir), de != NULL) {
341 len = strlen(de->d_name);
342 if (len < 5 || strcmp(de->d_name + len - 4, ".rpm") != 0)
344 snprintf(filename, sizeof filename,
345 "%s/%s", dirname, de->d_name);
346 rpm = razor_rpm_open(filename);
349 "failed to open rpm \"%s\"\n", filename);
352 if (razor_importer_add_rpm(importer, rpm)) {
353 fprintf(stderr, "couldn't import %s\n", filename);
356 razor_rpm_close(rpm);
360 razor_importer_destroy(importer);
364 set = razor_importer_finish(importer);
366 razor_set_write(set, repo_filename);
367 razor_set_destroy(set);
368 printf("wrote %s\n", repo_filename);
374 command_install(int argc, const char *argv[])
376 struct razor_rpm *rpm;
377 const char *filename = argv[0];
379 const char root[] = "install";
381 if (stat(root, &buf) < 0) {
382 if (mkdir(root, 0777) < 0) {
384 "could not create install root \"%s\"\n",
388 fprintf(stderr, "created install root \"%s\"\n", root);
389 } else if (!S_ISDIR(buf.st_mode)) {
391 "install root \"%s\" exists, but is not a directory\n",
396 rpm = razor_rpm_open(filename);
398 fprintf(stderr, "failed to open rpm %s\n", filename);
401 if (razor_rpm_install(rpm, root) < 0) {
402 fprintf(stderr, "failed to install rpm %s\n", filename);
406 razor_rpm_close(rpm);
413 const char *description;
414 int (*func)(int argc, const char *argv[]);
415 } razor_commands[] = {
416 { "list", "list all packages", command_list },
417 { "list-requires", "list all requires for the given package", command_list_requires },
418 { "list-provides", "list all provides for the given package", command_list_provides },
419 { "list-obsoletes", "list all obsoletes for the given package", command_list_obsoletes },
420 { "list-conflicts", "list all conflicts for the given package", command_list_conflicts },
421 { "list-files", "list files for package set", command_list_files },
422 { "list-file-packages", "list packages owning file", command_list_file_packages },
423 { "list-package-files", "list files in package", command_list_package_files },
424 { "what-requires", "list the packages that have the given requires", command_what_requires },
425 { "what-provides", "list the packages that have the given provides", command_what_provides },
426 { "import-yum", "import yum metadata files", command_import_yum },
427 { "import-rpmdb", "import the system rpm database", command_import_rpmdb },
428 { "import-rpms", "import rpms from the given directory", command_import_rpms },
429 { "validate", "validate a package set", command_validate },
430 { "update", "update all or specified packages", command_update },
431 { "diff", "show diff between two package sets", command_diff },
432 { "install", "install rpm", command_install }
441 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
443 razor_commands[i].name, razor_commands[i].description);
449 main(int argc, const char *argv[])
454 repo = getenv("RAZOR_REPO");
456 repo_filename = repo;
461 for (i = 0; i < ARRAY_SIZE(razor_commands); i++)
462 if (strcmp(razor_commands[i].name, argv[1]) == 0)
463 return razor_commands[i].func(argc - 2, argv + 2);