lib/package_alternatives.c: check if alternative is a symlink before removing it

Original commit by @duncaen ... but couldn't find this anywhere.
This commit is contained in:
Juan RP 2019-10-27 08:44:37 +01:00
parent 3854bd103f
commit 98e09e01e1
No known key found for this signature in database
GPG Key ID: AF19F6CB482F9368

View File

@ -111,6 +111,7 @@ static int
remove_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) remove_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname)
{ {
unsigned int i, cnt; unsigned int i, cnt;
struct stat st;
cnt = xbps_array_count(a); cnt = xbps_array_count(a);
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
@ -132,6 +133,11 @@ remove_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname)
} else { } else {
lnk = xbps_xasprintf("%s%s", xhp->rootdir, l); lnk = xbps_xasprintf("%s%s", xhp->rootdir, l);
} }
if (lstat(lnk, &st) == -1 || !S_ISLNK(st.st_mode)) {
free(lnk);
free(l);
continue;
}
xbps_set_cb_state(xhp, XBPS_STATE_ALTGROUP_LINK_REMOVED, 0, NULL, xbps_set_cb_state(xhp, XBPS_STATE_ALTGROUP_LINK_REMOVED, 0, NULL,
"Removing '%s' alternatives group symlink: %s", grname, l); "Removing '%s' alternatives group symlink: %s", grname, l);
unlink(lnk); unlink(lnk);