From: "Richard M. Stallman" <rms@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Race-condition ? (was: "Preserve owner and group" on MSDOS/Windows)
Date: Sun, 26 Jun 2005 00:46:54 -0400 [thread overview]
Message-ID: <E1DmP2k-0006uH-S0@fencepost.gnu.org> (raw)
In-Reply-To: <qlkbr5vdc8i.fsf@clipper.ens.fr> (gaetan.leurent@ens.fr)
How about this fix?
*** fileio.c 24 Jun 2005 15:43:20 -0400 1.547
--- fileio.c 25 Jun 2005 16:56:28 -0400
***************
*** 2406,2412 ****
return;
}
! DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 5,
"fCopy file: \nGCopy %s to file: \np\nP",
doc: /* Copy FILE to NEWNAME. Both args must be strings.
If NEWNAME names a directory, copy FILE there.
--- 2406,2412 ----
return;
}
! DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 6,
"fCopy file: \nGCopy %s to file: \np\nP",
doc: /* Copy FILE to NEWNAME. Both args must be strings.
If NEWNAME names a directory, copy FILE there.
***************
*** 2426,2434 ****
that means to get an error if the file already exists; never overwrite.
If MUSTBENEW is neither nil nor `excl', that means ask for
confirmation before overwriting, but do go ahead and overwrite the file
! if the user confirms. */)
! (file, newname, ok_if_already_exists, keep_time, mustbenew)
Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew;
{
int ifd, ofd, n;
char buf[16 * 1024];
--- 2426,2438 ----
that means to get an error if the file already exists; never overwrite.
If MUSTBENEW is neither nil nor `excl', that means ask for
confirmation before overwriting, but do go ahead and overwrite the file
! if the user confirms.
!
! If PRESERVE-UID-GID is non-nil, we try to transfer the
! uid and gid of FILE to NEWNAME. */)
! (file, newname, ok_if_already_exists, keep_time, mustbenew, preserve_uid_gid)
Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew;
+ Lisp_Object preserve_uid_gid;
{
int ifd, ofd, n;
char buf[16 * 1024];
***************
*** 2570,2575 ****
--- 2574,2599 ----
report_file_error ("I/O error", Fcons (newname, Qnil));
immediate_quit = 0;
+ /* Preserve the owner and group, if requested. */
+ if (input_file_statable_p && ! NILP (preserve_uid_gid))
+ fchown (ofd, st.st_uid, st.st_gid);
+
+ if (input_file_statable_p)
+ {
+ #ifndef MSDOS
+ fchmod (ofd, st.st_mode & 07777);
+ #else /* MSDOS */
+ #if defined (__DJGPP__) && __DJGPP__ > 1
+ /* In DJGPP v2.0 and later, fstat usually returns true file mode bits,
+ and if it can't, it tells so. Otherwise, under MSDOS we usually
+ get only the READ bit, which will make the copied file read-only,
+ so it's better not to chmod at all. */
+ if ((_djstat_flags & _STFAIL_WRITEBIT) == 0)
+ chmod (SDATA (encoded_newname), st.st_mode & 07777);
+ #endif /* DJGPP version 2 or newer */
+ #endif /* MSDOS */
+ }
+
/* Closing the output clobbers the file times on some systems. */
if (emacs_close (ofd) < 0)
report_file_error ("I/O error", Fcons (newname, Qnil));
***************
*** 2587,2604 ****
Fcons (build_string ("Cannot set file date"),
Fcons (newname, Qnil)));
}
- #ifndef MSDOS
- chmod (SDATA (encoded_newname), st.st_mode & 07777);
- #else /* MSDOS */
- #if defined (__DJGPP__) && __DJGPP__ > 1
- /* In DJGPP v2.0 and later, fstat usually returns true file mode bits,
- and if it can't, it tells so. Otherwise, under MSDOS we usually
- get only the READ bit, which will make the copied file read-only,
- so it's better not to chmod at all. */
- if ((_djstat_flags & _STFAIL_WRITEBIT) == 0)
- chmod (SDATA (encoded_newname), st.st_mode & 07777);
- #endif /* DJGPP version 2 or newer */
- #endif /* MSDOS */
}
emacs_close (ifd);
--- 2611,2616 ----
***************
*** 2775,2781 ****
{
if (errno == EXDEV)
{
- struct stat data;
#ifdef S_IFLNK
symlink_target = Ffile_symlink_p (file);
if (! NILP (symlink_target))
--- 2787,2792 ----
***************
*** 2783,2797 ****
NILP (ok_if_already_exists) ? Qnil : Qt);
else
#endif
! Fcopy_file (file, newname,
! /* We have already prompted if it was an integer,
! 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);
}
--- 2794,2804 ----
NILP (ok_if_already_exists) ? Qnil : Qt);
else
#endif
! Fcopy_file (file, newname,
! /* We have already prompted if it was an integer,
! so don't have copy-file prompt again. */
! NILP (ok_if_already_exists) ? Qnil : Qt,
! Qt, Qnil, Qt);
Fdelete_file (file);
}
next prev parent reply other threads:[~2005-06-26 4:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-24 9:08 "Preserve owner and group" on MSDOS/Windows Juanma Barranquero
2005-06-24 11:45 ` Eli Zaretskii
2005-06-24 11:02 ` Juanma Barranquero
2005-06-24 15:07 ` Race-condition ? (was: "Preserve owner and group" on MSDOS/Windows) Gaëtan LEURENT
2005-06-24 20:07 ` Eli Zaretskii
2005-06-24 20:46 ` Race-condition ? Gaëtan LEURENT
2005-06-25 9:27 ` Eli Zaretskii
2005-06-24 21:01 ` David Kastrup
2005-06-25 22:25 ` Gaëtan LEURENT
2005-06-26 18:48 ` David Kastrup
2005-06-26 4:46 ` Race-condition ? (was: "Preserve owner and group" on MSDOS/Windows) Richard M. Stallman
2005-06-26 19:52 ` Race-condition ? Gaëtan LEURENT
2005-06-27 5:38 ` Richard M. Stallman
2005-06-28 22:57 ` Gaëtan LEURENT
2005-06-28 23:50 ` Lennart Borgman
2005-06-30 5:42 ` David Kastrup
2005-07-03 15:49 ` Richard M. Stallman
2005-06-26 4:46 ` Richard M. Stallman [this message]
2005-06-26 17:12 ` Gaëtan LEURENT
2005-06-26 18:59 ` Race-condition ? (was: "Preserve owner and group" on MSDOS/Windows) Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1DmP2k-0006uH-S0@fencepost.gnu.org \
--to=rms@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).