diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-pkgdb/main.c index 1b3d4dcdfe6..6e47bd0f350 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-pkgdb/main.c @@ -155,14 +155,13 @@ main(int argc, char **argv) if (argc != 3) usage(); - if (!xbps_remove_pkg_dict_from_file(argv[1], plist)) { - if (errno == ENODEV) - printf("=> ERROR: %s not registered " - "in database.\n", argv[1]); - else - printf("=> ERROR: couldn't unregister %s " - "from database (%s)\n", argv[1], - strerror(errno)); + rv = xbps_remove_pkg_dict_from_file(argv[1], plist); + if (rv == ENOENT) { + printf("=> ERROR: %s not registered in database.\n", + argv[1]); + } else { + printf("=> ERROR: couldn't unregister %s " + "from database (%s)\n", argv[1], strerror(rv)); exit(EXIT_FAILURE); } diff --git a/bin/xbps-repo/index.c b/bin/xbps-repo/index.c index 02e00b88b0e..b00c814c9f2 100644 --- a/bin/xbps-repo/index.c +++ b/bin/xbps-repo/index.c @@ -176,10 +176,10 @@ repoidx_addpkg(const char *file, const char *filename, const char *pkgdir) * registered actually, remove old package from * the index. */ - if (!xbps_remove_pkg_from_dict(idxdict, - "packages", pkgname)) { + rv = xbps_remove_pkg_from_dict(idxdict, + "packages", pkgname); + if (rv != 0) { prop_object_release(newpkgd); - rv = EINVAL; break; } } diff --git a/include/xbps_api.h b/include/xbps_api.h index 44e69427ca1..7d747c4ac9d 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -114,8 +114,8 @@ bool xbps_find_string_in_array(prop_array_t, const char *); prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t, const char *); -bool xbps_remove_pkg_dict_from_file(const char *, const char *); -bool xbps_remove_pkg_from_dict(prop_dictionary_t, const char *, +int xbps_remove_pkg_dict_from_file(const char *, const char *); +int xbps_remove_pkg_from_dict(prop_dictionary_t, const char *, const char *); int xbps_remove_string_from_array(prop_array_t, const char *); diff --git a/lib/depends.c b/lib/depends.c index 2cd62714fe2..2934b078b83 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -341,13 +341,12 @@ find_pkg_missing_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg) if ((rv = store_dependency(pkg, curpkgd, repo)) != 0) break; /* - * Remove package from missing now. + * Remove package from missing_deps array now. */ - if (!xbps_remove_pkg_from_dict(chaindeps, - "missing_deps", pkgname)) { - if (errno != 0 && errno != ENOENT) - break; - } + rv = xbps_remove_pkg_from_dict(chaindeps, + "missing_deps", pkgname); + if (rv != 0 && rv != ENOENT) + break; prop_object_iterator_reset(iter); } @@ -444,12 +443,11 @@ find_pkg_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg, /* * Remove package from missing_deps now it's been found. */ - if (!xbps_remove_pkg_from_dict(chaindeps, - "missing_deps", pkgname)) { - if (errno != 0 && errno != ENOENT) { - free(pkgname); - break; - } + rv = xbps_remove_pkg_from_dict(chaindeps, + "missing_deps", pkgname); + if (rv != 0 && rv != ENOENT) { + free(pkgname); + break; } free(pkgname); diff --git a/lib/plist.c b/lib/plist.c index 461380809de..67239617423 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -276,7 +276,7 @@ xbps_remove_string_from_array(prop_array_t array, const char *str) return 0; } -bool +int xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key, const char *pkgname) { @@ -293,11 +293,11 @@ xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key, array = prop_dictionary_get(dict, key); if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) - return false; + return EINVAL; iter = prop_array_iterator(array); if (iter == NULL) - return false; + return errno; /* Iterate over the array of dictionaries to find its index. */ while ((obj = prop_object_iterator_next(iter))) { @@ -313,35 +313,36 @@ xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key, if (found == true) prop_array_remove(array, i); else - errno = ENOENT; + return ENOENT; - return found; + return 0; } -bool +int xbps_remove_pkg_dict_from_file(const char *pkg, const char *plist) { prop_dictionary_t pdict; + int rv = 0; assert(pkg != NULL); assert(plist != NULL); pdict = prop_dictionary_internalize_from_file(plist); if (pdict == NULL) - return false; + return errno; - if (!xbps_remove_pkg_from_dict(pdict, "packages", pkg)) { + rv = xbps_remove_pkg_from_dict(pdict, "packages", pkg); + if (rv != 0) { prop_object_release(pdict); - errno = ENODEV; - return false; + return rv; } if (!prop_dictionary_externalize_to_file(pdict, plist)) { prop_object_release(pdict); - return false; + return errno; } prop_object_release(pdict); - return true; + return 0; } diff --git a/lib/remove.c b/lib/remove.c index d3fc0d71ef0..797d6ab4c7c 100644 --- a/lib/remove.c +++ b/lib/remove.c @@ -53,9 +53,7 @@ xbps_unregister_pkg(const char *pkgname) if (plist == NULL) return EINVAL; - if (!xbps_remove_pkg_dict_from_file(pkgname, plist)) - rv = errno; - + rv = xbps_remove_pkg_dict_from_file(pkgname, plist); free(plist); return rv;