Improve detection of target file in relative symlinks.
If xbps-create(8) did not guess the target file of relative symlinks for some reason, just compare the current symlink and what's stored as is, without converting it to absolute. This might happen with dangling relative symlinks or existing binary packages that were not created with a newer xbps-create(8).
This commit is contained in:
@@ -211,14 +211,14 @@ remove_pkg_files(struct xbps_handle *xhp,
|
||||
const char *target = NULL;
|
||||
char *lnk;
|
||||
|
||||
lnk = xbps_symlink_target(xhp, path);
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "target", &target);
|
||||
assert(target);
|
||||
lnk = xbps_symlink_target(xhp, path, target);
|
||||
if (lnk == NULL) {
|
||||
xbps_dbg_printf(xhp, "[remove] %s "
|
||||
"symlink_target: %s\n", path, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "target", &target);
|
||||
assert(target);
|
||||
if (strcmp(lnk, target)) {
|
||||
xbps_dbg_printf(xhp, "[remove] %s symlink "
|
||||
"modified (stored %s current %s)\n", path,
|
||||
|
||||
11
lib/util.c
11
lib/util.c
@@ -454,7 +454,7 @@ xbps_sanitize_path(const char *src)
|
||||
}
|
||||
|
||||
char *
|
||||
xbps_symlink_target(struct xbps_handle *xhp, const char *path)
|
||||
xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt)
|
||||
{
|
||||
struct stat sb;
|
||||
char *p, *p1, *dname, *res = NULL, *lnk = NULL;
|
||||
@@ -472,6 +472,15 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path)
|
||||
return NULL;
|
||||
}
|
||||
lnk[sb.st_size] = '\0';
|
||||
|
||||
if (tgt[0] != '/') {
|
||||
/*
|
||||
* target file is relative and wasn't converted to absolute by
|
||||
* xbps-create(8), just compare it as is.
|
||||
*/
|
||||
return lnk;
|
||||
}
|
||||
|
||||
if (strstr(lnk, "./") || lnk[0] != '/') {
|
||||
/* relative */
|
||||
p = strdup(path);
|
||||
|
||||
Reference in New Issue
Block a user