2406 |
return; |
return; |
2407 |
} |
} |
2408 |
|
|
2409 |
DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 5, |
DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 6, |
2410 |
"fCopy file: \nGCopy %s to file: \np\nP", |
"fCopy file: \nGCopy %s to file: \np\nP", |
2411 |
doc: /* Copy FILE to NEWNAME. Both args must be strings. |
doc: /* Copy FILE to NEWNAME. Both args must be strings. |
2412 |
If NEWNAME names a directory, copy FILE there. |
If NEWNAME names a directory, copy FILE there. |
2426 |
that means to get an error if the file already exists; never overwrite. |
that means to get an error if the file already exists; never overwrite. |
2427 |
If MUSTBENEW is neither nil nor `excl', that means ask for |
If MUSTBENEW is neither nil nor `excl', that means ask for |
2428 |
confirmation before overwriting, but do go ahead and overwrite the file |
confirmation before overwriting, but do go ahead and overwrite the file |
2429 |
if the user confirms. */) |
if the user confirms. |
2430 |
(file, newname, ok_if_already_exists, keep_time, mustbenew) |
|
2431 |
|
If PRESERVE-UID-GID is non-nil, we try to transfer the |
2432 |
|
uid and gid of FILE to NEWNAME. */) |
2433 |
|
(file, newname, ok_if_already_exists, keep_time, mustbenew, preserve_uid_gid) |
2434 |
Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew; |
Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew; |
2435 |
|
Lisp_Object preserve_uid_gid; |
2436 |
{ |
{ |
2437 |
int ifd, ofd, n; |
int ifd, ofd, n; |
2438 |
char buf[16 * 1024]; |
char buf[16 * 1024]; |
2574 |
report_file_error ("I/O error", Fcons (newname, Qnil)); |
report_file_error ("I/O error", Fcons (newname, Qnil)); |
2575 |
immediate_quit = 0; |
immediate_quit = 0; |
2576 |
|
|
2577 |
|
/* Preserve the owner and group, if requested. */ |
2578 |
|
if (input_file_statable_p && ! NILP (preserve_uid_gid)) |
2579 |
|
fchown (ofd, st.st_uid, st.st_gid); |
2580 |
|
|
2581 |
|
if (input_file_statable_p) |
2582 |
|
{ |
2583 |
|
#ifndef MSDOS |
2584 |
|
fchmod (ofd, st.st_mode & 07777); |
2585 |
|
#else /* MSDOS */ |
2586 |
|
#if defined (__DJGPP__) && __DJGPP__ > 1 |
2587 |
|
/* In DJGPP v2.0 and later, fstat usually returns true file mode bits, |
2588 |
|
and if it can't, it tells so. Otherwise, under MSDOS we usually |
2589 |
|
get only the READ bit, which will make the copied file read-only, |
2590 |
|
so it's better not to chmod at all. */ |
2591 |
|
if ((_djstat_flags & _STFAIL_WRITEBIT) == 0) |
2592 |
|
chmod (SDATA (encoded_newname), st.st_mode & 07777); |
2593 |
|
#endif /* DJGPP version 2 or newer */ |
2594 |
|
#endif /* MSDOS */ |
2595 |
|
} |
2596 |
|
|
2597 |
/* Closing the output clobbers the file times on some systems. */ |
/* Closing the output clobbers the file times on some systems. */ |
2598 |
if (emacs_close (ofd) < 0) |
if (emacs_close (ofd) < 0) |
2599 |
report_file_error ("I/O error", Fcons (newname, Qnil)); |
report_file_error ("I/O error", Fcons (newname, Qnil)); |
2611 |
Fcons (build_string ("Cannot set file date"), |
Fcons (build_string ("Cannot set file date"), |
2612 |
Fcons (newname, Qnil))); |
Fcons (newname, Qnil))); |
2613 |
} |
} |
|
#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 */ |
|
2614 |
} |
} |
2615 |
|
|
2616 |
emacs_close (ifd); |
emacs_close (ifd); |
2787 |
{ |
{ |
2788 |
if (errno == EXDEV) |
if (errno == EXDEV) |
2789 |
{ |
{ |
|
struct stat data; |
|
2790 |
#ifdef S_IFLNK |
#ifdef S_IFLNK |
2791 |
symlink_target = Ffile_symlink_p (file); |
symlink_target = Ffile_symlink_p (file); |
2792 |
if (! NILP (symlink_target)) |
if (! NILP (symlink_target)) |
2794 |
NILP (ok_if_already_exists) ? Qnil : Qt); |
NILP (ok_if_already_exists) ? Qnil : Qt); |
2795 |
else |
else |
2796 |
#endif |
#endif |
2797 |
Fcopy_file (file, newname, |
Fcopy_file (file, newname, |
2798 |
/* We have already prompted if it was an integer, |
/* We have already prompted if it was an integer, |
2799 |
so don't have copy-file prompt again. */ |
so don't have copy-file prompt again. */ |
2800 |
NILP (ok_if_already_exists) ? Qnil : Qt, |
NILP (ok_if_already_exists) ? Qnil : Qt, |
2801 |
Qt, Qnil); |
Qt, Qnil, Qt); |
|
|
|
|
/* 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); |
|
2802 |
|
|
2803 |
Fdelete_file (file); |
Fdelete_file (file); |
2804 |
} |
} |