When removing pkg files, remove only dangling symlinks after regular files.

This is required for the upcoming eglibc package.
This commit is contained in:
Juan RP 2012-05-25 14:31:42 +02:00
parent a14886ab48
commit d075f7182a
3 changed files with 31 additions and 4 deletions

9
NEWS
View File

@ -1,5 +1,14 @@
xbps-0.16 (???):
* libxbps: change the order in which package files are removed:
current: files, conf_files, links, directories.
previous: links, files, conf_files, directories.
This is required to avoid removing working symlinks, which could be
owned by another installed package. Now only dangling symlinks are now
removed.
* libxbps: when removing package files and if metadata files.plist wasn't
found, do not error out and rather just continue until the package is
fully removed.

View File

@ -56,7 +56,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.4"
#define XBPS_API_VERSION "20120521"
#define XBPS_API_VERSION "20120525"
#define XBPS_VERSION "0.16"
/**

View File

@ -131,11 +131,13 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
const char *pkgver)
{
struct xbps_handle *xhp;
struct stat st;
prop_array_t array;
prop_object_iterator_t iter;
prop_object_t obj;
const char *file, *sha256, *version, *curobj = NULL;
char *path = NULL, *pkgname = NULL;
char buf[PATH_MAX];
int rv = 0;
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
@ -220,6 +222,22 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
free(path);
break;
}
} else if (strcmp(key, "links") == 0) {
/*
* All regular files from package were removed at this
* point, so we will only remove dangling symlinks.
*/
if (realpath(path, buf) == NULL) {
if (errno != ENOENT) {
free(path);
rv = errno;
break;
}
}
if (stat(buf, &st) == 0) {
free(path);
continue;
}
}
/*
* Remove the object if possible.
@ -329,15 +347,15 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
pkgd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
if (pkgd) {
/* Remove links */
if ((rv = xbps_remove_pkg_files(pkgd, "links", pkgver)) != 0)
goto out;
/* Remove regular files */
if ((rv = xbps_remove_pkg_files(pkgd, "files", pkgver)) != 0)
goto out;
/* Remove configuration files */
if ((rv = xbps_remove_pkg_files(pkgd, "conf_files", pkgver)) != 0)
goto out;
/* Remove links */
if ((rv = xbps_remove_pkg_files(pkgd, "links", pkgver)) != 0)
goto out;
/* Remove dirs */
if ((rv = xbps_remove_pkg_files(pkgd, "dirs", pkgver)) != 0)
goto out;