- if (chown (file_name, st->stat.st_uid, st->stat.st_gid) < 0)
- chown_error_details (file_name,
- st->stat.st_uid, st->stat.st_gid);
-
- /* On a few systems, and in particular, those allowing to give files
- away, changing the owner or group destroys the suid or sgid bits.
- So let's attempt setting these bits once more. */
- if (st->stat.st_mode & (S_ISUID | S_ISGID | S_ISVTX))
- set_mode (file_name, &st->stat, 0,
- invert_permissions, permstatus, typeflag);
+ chown_result = chown (file_name, st->stat.st_uid, st->stat.st_gid);
+ }
+
+ if (chown_result == 0)
+ {
+ /* Changing the owner can flip st_mode bits in some cases, so
+ ignore cur_info if it might be obsolete now. */
+ if (cur_info
+ && cur_info->st_mode & S_IXUGO
+ && cur_info->st_mode & (S_ISUID | S_ISGID))
+ cur_info = NULL;