1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-20 18:56:39 +02:00

(rpl_chown): Work even if the file is writeable but not readable.

This commit is contained in:
Paul Eggert
2004-08-09 23:33:53 +00:00
parent 3038f02225
commit 1ff6d6ea07

View File

@@ -68,10 +68,11 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
/* Handle the case in which the system-supplied chown function
does *not* follow symlinks. Instead, it changes permissions
on the symlink itself. To work around that, we open the
file (but this can fail due to lack of read permission) and
file (but this can fail due to lack of read or write permission) and
use fchown on the resulting descriptor. */
int fd = open (file, O_RDONLY | O_NONBLOCK | O_NOCTTY);
if (fd == -1)
if (fd < 0
&& (fd = open (file, O_WRONLY | O_NONBLOCK | O_NOCTTY)) < 0)
return -1;
if (fchown (fd, uid, gid))
{