Make xbps_remove_pkg_from_* return int rather than bool.

--HG--
extra : convert_revision : 9f413873669b552a4d7a6e25e667fe5ff43f6a78
This commit is contained in:
Juan RP 2009-04-06 16:39:14 +02:00
parent 147a8af559
commit 625a77883c
6 changed files with 36 additions and 40 deletions

View file

@ -155,14 +155,13 @@ main(int argc, char **argv)
if (argc != 3) if (argc != 3)
usage(); usage();
if (!xbps_remove_pkg_dict_from_file(argv[1], plist)) { rv = xbps_remove_pkg_dict_from_file(argv[1], plist);
if (errno == ENODEV) if (rv == ENOENT) {
printf("=> ERROR: %s not registered " printf("=> ERROR: %s not registered in database.\n",
"in database.\n", argv[1]); argv[1]);
else } else {
printf("=> ERROR: couldn't unregister %s " printf("=> ERROR: couldn't unregister %s "
"from database (%s)\n", argv[1], "from database (%s)\n", argv[1], strerror(rv));
strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

View file

@ -176,10 +176,10 @@ repoidx_addpkg(const char *file, const char *filename, const char *pkgdir)
* registered actually, remove old package from * registered actually, remove old package from
* the index. * the index.
*/ */
if (!xbps_remove_pkg_from_dict(idxdict, rv = xbps_remove_pkg_from_dict(idxdict,
"packages", pkgname)) { "packages", pkgname);
if (rv != 0) {
prop_object_release(newpkgd); prop_object_release(newpkgd);
rv = EINVAL;
break; break;
} }
} }

View file

@ -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, prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t,
const char *); const char *);
bool xbps_remove_pkg_dict_from_file(const char *, const char *); int 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_from_dict(prop_dictionary_t, const char *,
const char *); const char *);
int xbps_remove_string_from_array(prop_array_t, const char *); int xbps_remove_string_from_array(prop_array_t, const char *);

View file

@ -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) if ((rv = store_dependency(pkg, curpkgd, repo)) != 0)
break; break;
/* /*
* Remove package from missing now. * Remove package from missing_deps array now.
*/ */
if (!xbps_remove_pkg_from_dict(chaindeps, rv = xbps_remove_pkg_from_dict(chaindeps,
"missing_deps", pkgname)) { "missing_deps", pkgname);
if (errno != 0 && errno != ENOENT) if (rv != 0 && rv != ENOENT)
break; break;
}
prop_object_iterator_reset(iter); 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. * Remove package from missing_deps now it's been found.
*/ */
if (!xbps_remove_pkg_from_dict(chaindeps, rv = xbps_remove_pkg_from_dict(chaindeps,
"missing_deps", pkgname)) { "missing_deps", pkgname);
if (errno != 0 && errno != ENOENT) { if (rv != 0 && rv != ENOENT) {
free(pkgname); free(pkgname);
break; break;
}
} }
free(pkgname); free(pkgname);

View file

@ -276,7 +276,7 @@ xbps_remove_string_from_array(prop_array_t array, const char *str)
return 0; return 0;
} }
bool int
xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key, xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key,
const char *pkgname) 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); array = prop_dictionary_get(dict, key);
if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY)
return false; return EINVAL;
iter = prop_array_iterator(array); iter = prop_array_iterator(array);
if (iter == NULL) if (iter == NULL)
return false; return errno;
/* Iterate over the array of dictionaries to find its index. */ /* Iterate over the array of dictionaries to find its index. */
while ((obj = prop_object_iterator_next(iter))) { 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) if (found == true)
prop_array_remove(array, i); prop_array_remove(array, i);
else else
errno = ENOENT; return ENOENT;
return found; return 0;
} }
bool int
xbps_remove_pkg_dict_from_file(const char *pkg, const char *plist) xbps_remove_pkg_dict_from_file(const char *pkg, const char *plist)
{ {
prop_dictionary_t pdict; prop_dictionary_t pdict;
int rv = 0;
assert(pkg != NULL); assert(pkg != NULL);
assert(plist != NULL); assert(plist != NULL);
pdict = prop_dictionary_internalize_from_file(plist); pdict = prop_dictionary_internalize_from_file(plist);
if (pdict == NULL) 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); prop_object_release(pdict);
errno = ENODEV; return rv;
return false;
} }
if (!prop_dictionary_externalize_to_file(pdict, plist)) { if (!prop_dictionary_externalize_to_file(pdict, plist)) {
prop_object_release(pdict); prop_object_release(pdict);
return false; return errno;
} }
prop_object_release(pdict); prop_object_release(pdict);
return true; return 0;
} }

View file

@ -53,9 +53,7 @@ xbps_unregister_pkg(const char *pkgname)
if (plist == NULL) if (plist == NULL)
return EINVAL; return EINVAL;
if (!xbps_remove_pkg_dict_from_file(pkgname, plist)) rv = xbps_remove_pkg_dict_from_file(pkgname, plist);
rv = errno;
free(plist); free(plist);
return rv; return rv;