aboutsummaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 84b32f8dda9..8ce89ba23f3 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2409,32 +2409,31 @@ barf_or_query_if_file_exists (absname, querystring, interactive, statptr, quick)
2409 return; 2409 return;
2410} 2410}
2411 2411
2412DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 6, 2412DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 5,
2413 "fCopy file: \nGCopy %s to file: \np\nP", 2413 "fCopy file: \nGCopy %s to file: \np\nP",
2414 doc: /* Copy FILE to NEWNAME. Both args must be strings. 2414 doc: /* Copy FILE to NEWNAME. Both args must be strings.
2415If NEWNAME names a directory, copy FILE there. 2415If NEWNAME names a directory, copy FILE there.
2416Signals a `file-already-exists' error if file NEWNAME already exists, 2416
2417unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. 2417This function always sets the file modes of the output file to match
2418A number as third arg means request confirmation if NEWNAME already exists. 2418the input file.
2419This is what happens in interactive use with M-x. 2419
2420Always sets the file modes of the output file to match the input file. 2420The optional third argument OK-IF-ALREADY-EXISTS specifies what to do
2421if file NEWNAME already exists. If OK-IF-ALREADY-EXISTS is nil, we
2422signal a `file-already-exists' error without overwriting. If
2423OK-IF-ALREADY-EXISTS is a number, we request confirmation from the user
2424about overwriting; this is what happens in interactive use with M-x.
2425Any other value for OK-IF-ALREADY-EXISTS means to overwrite the
2426existing file.
2421 2427
2422Fourth arg KEEP-TIME non-nil means give the output file the same 2428Fourth arg KEEP-TIME non-nil means give the output file the same
2423last-modified time as the old one. (This works on only some systems.) 2429last-modified time as the old one. (This works on only some systems.)
2424 2430
2425A prefix arg makes KEEP-TIME non-nil. 2431A prefix arg makes KEEP-TIME non-nil.
2426 2432
2427The optional fifth arg MUSTBENEW, if non-nil, insists on a check
2428for an existing file with the same name. If MUSTBENEW is `excl',
2429that means to get an error if the file already exists; never overwrite.
2430If MUSTBENEW is neither nil nor `excl', that means ask for
2431confirmation before overwriting, but do go ahead and overwrite the file
2432if the user confirms.
2433
2434If PRESERVE-UID-GID is non-nil, we try to transfer the 2433If PRESERVE-UID-GID is non-nil, we try to transfer the
2435uid and gid of FILE to NEWNAME. */) 2434uid and gid of FILE to NEWNAME. */)
2436 (file, newname, ok_if_already_exists, keep_time, mustbenew, preserve_uid_gid) 2435 (file, newname, ok_if_already_exists, keep_time, preserve_uid_gid)
2437 Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew; 2436 Lisp_Object file, newname, ok_if_already_exists, keep_time;
2438 Lisp_Object preserve_uid_gid; 2437 Lisp_Object preserve_uid_gid;
2439{ 2438{
2440 int ifd, ofd, n; 2439 int ifd, ofd, n;
@@ -2451,9 +2450,6 @@ uid and gid of FILE to NEWNAME. */)
2451 CHECK_STRING (file); 2450 CHECK_STRING (file);
2452 CHECK_STRING (newname); 2451 CHECK_STRING (newname);
2453 2452
2454 if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl))
2455 barf_or_query_if_file_exists (newname, "overwrite", 1, 0, 1);
2456
2457 if (!NILP (Ffile_directory_p (newname))) 2453 if (!NILP (Ffile_directory_p (newname)))
2458 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); 2454 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
2459 else 2455 else
@@ -2556,12 +2552,12 @@ uid and gid of FILE to NEWNAME. */)
2556 /* System's default file type was set to binary by _fmode in emacs.c. */ 2552 /* System's default file type was set to binary by _fmode in emacs.c. */
2557 ofd = emacs_open (SDATA (encoded_newname), 2553 ofd = emacs_open (SDATA (encoded_newname),
2558 O_WRONLY | O_TRUNC | O_CREAT 2554 O_WRONLY | O_TRUNC | O_CREAT
2559 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0), 2555 | (NILP (ok_if_already_exists) ? O_EXCL : 0),
2560 S_IREAD | S_IWRITE); 2556 S_IREAD | S_IWRITE);
2561#else /* not MSDOS */ 2557#else /* not MSDOS */
2562 ofd = emacs_open (SDATA (encoded_newname), 2558 ofd = emacs_open (SDATA (encoded_newname),
2563 O_WRONLY | O_TRUNC | O_CREAT 2559 O_WRONLY | O_TRUNC | O_CREAT
2564 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0), 2560 | (NILP (ok_if_already_exists) ? O_EXCL : 0),
2565 0666); 2561 0666);
2566#endif /* not MSDOS */ 2562#endif /* not MSDOS */
2567#endif /* VMS */ 2563#endif /* VMS */
@@ -2806,7 +2802,7 @@ This is what happens in interactive use with M-x. */)
2806 /* We have already prompted if it was an integer, 2802 /* We have already prompted if it was an integer,
2807 so don't have copy-file prompt again. */ 2803 so don't have copy-file prompt again. */
2808 NILP (ok_if_already_exists) ? Qnil : Qt, 2804 NILP (ok_if_already_exists) ? Qnil : Qt,
2809 Qt, Qnil, Qt); 2805 Qt, Qt);
2810 2806
2811 Fdelete_file (file); 2807 Fdelete_file (file);
2812 } 2808 }