]> code.delx.au - gnu-emacs/blobdiff - src/fileio.c
Merged from miles@gnu.org--gnu-2005 (patch 441-446)
[gnu-emacs] / src / fileio.c
index c38cb924c8b3a533fbd628f35bf887bc5a2a10d4..075f12ccb21f8fe5729d65f7a14299885435d7ec 100644 (file)
@@ -2777,6 +2777,7 @@ This is what happens in interactive use with M-x.  */)
     {
       if (errno == EXDEV)
        {
+         struct stat data;
 #ifdef S_IFLNK
           symlink_target = Ffile_symlink_p (file);
           if (! NILP (symlink_target))
@@ -2789,6 +2790,11 @@ This is what happens in interactive use with M-x.  */)
                            so don't have copy-file prompt again.  */
                         NILP (ok_if_already_exists) ? Qnil : Qt,
                        Qt, Qnil);
+
+         /* Preserve owner and group, if possible (if we are root).  */
+         if (stat (SDATA (encoded_file), &data) >= 0)
+           chown (SDATA (encoded_file), data.st_uid, data.st_gid);
+
          Fdelete_file (file);
        }
       else