Skip to content

Commit dff0e9a

Browse files
committed
lib: fix use of undefined errno
1 parent 4a69184 commit dff0e9a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/package_remove.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,24 @@ check_remove_pkg_files(struct xbps_handle *xhp,
5555
* Check if effective user ID owns the file; this is
5656
* enough to ensure the user has write permissions
5757
* on the directory.
58+
* XXX: this isn't really correct, would need to check parent
59+
* directory permissions...
5860
*/
59-
if (lstat(file, &st) == 0 && euid == st.st_uid) {
60-
/* success */
61-
continue;
61+
if (lstat(file, &st) == 0) {
62+
if (euid == st.st_uid)
63+
continue;
64+
errno = EPERM;
6265
}
6366
if (errno != ENOENT) {
6467
/*
6568
* only bail out if something else than ENOENT
6669
* is returned.
6770
*/
68-
int rv = errno;
69-
if (rv == 0) {
70-
/* lstat succeeds but euid != uid */
71-
rv = EPERM;
72-
}
7371
fail = true;
7472
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
75-
rv, pkgver,
76-
"%s: cannot remove `%s': %s",
77-
pkgver, file, strerror(rv));
73+
errno, pkgver, "%s: cannot remove `%s': %s", pkgver,
74+
file, strerror(errno));
7875
}
79-
errno = 0;
8076
}
8177
return fail;
8278
}

0 commit comments

Comments
 (0)