This is a safer approach, which handles cases in which a file would have
less permissions for a group than others.
A rare edge case, but let's be safe than sorry.
Reported-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
ub.actime = sb->st_atime;
ub.modtime = sb->st_mtime;
if ( (utime (backup, &ub) != 0)
- || (fchmod(fileno(bkfp), sb->st_mode) != 0)
- || (fchown(fileno(bkfp), sb->st_uid, sb->st_gid) != 0)) {
+ || (fchown(fileno(bkfp), sb->st_uid, sb->st_gid) != 0)
+ || (fchmod(fileno(bkfp), sb->st_mode) != 0)) {
fclose(bkfp);
unlink (backup);
return -1;