libxbps: xbps_repository_unregister(): in remote repositories, also

remove the pkg index file and its directory.
This commit is contained in:
Juan RP 2010-10-29 09:10:41 +02:00
parent 49a356df81
commit 8051232e82
2 changed files with 44 additions and 4 deletions

5
NEWS
View File

@ -1,5 +1,10 @@
xbps-0.6.2 (???):
* libxbps: xbps_repository_unregister(): in remote repositories, also
remove the pkg index file and its directory.
* libxbps: xbps_get_pkg_index_plist(): fixed a memleak.
* xbps-bin(8): modify the 'list' target to accept an optional argument to
list packages in the specified state, so that you can list packages that
need to be purged, configured and broken (will be used in the future).

View File

@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libgen.h>
#include <xbps_api.h>
@ -117,7 +118,8 @@ xbps_repository_unregister(const char *uri)
{
prop_dictionary_t dict;
prop_array_t array;
char *plist;
const char *pkgindexdir;
char *plist, *pkgindex;
int rv = 0;
assert(uri != NULL);
@ -139,11 +141,44 @@ xbps_repository_unregister(const char *uri)
goto out;
}
rv = xbps_remove_string_from_array(array, uri);
if (rv == 0) {
if ((rv = xbps_remove_string_from_array(array, uri)) == 0) {
/* Update plist file. */
if (!prop_dictionary_externalize_to_zfile(dict, plist))
if (!prop_dictionary_externalize_to_zfile(dict, plist)) {
rv = errno;
goto out;
}
}
/*
* If it's a remote repository, also remove the stored XBPS_PKGINDEX
* file and its directory.
*/
if (xbps_check_is_repo_string_remote(uri)) {
pkgindex = xbps_get_pkg_index_plist(uri);
if (pkgindex == NULL) {
rv = EINVAL;
goto out;
}
if (unlink(pkgindex) == -1) {
if (errno == ENOENT) {
free(pkgindex);
goto out;
}
fprintf(stderr, "E: cannot remove pkgindex file at "
"%s: %s\n", pkgindex, strerror(errno));
free(pkgindex);
rv = errno;
goto out;
}
pkgindexdir = dirname(pkgindex);
if (rmdir(pkgindexdir) == -1) {
fprintf(stderr, "E: cannot remove pkgindex dir at "
"%s: %s\n", pkgindexdir, strerror(errno));
free(pkgindex);
rv = errno;
goto out;
}
free(pkgindex);
}
out: