aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman2005-04-23 16:19:37 +0000
committerRichard M. Stallman2005-04-23 16:19:37 +0000
commitc50f15d05a0f7da0a2e5a36e9bf8c626c5817d6b (patch)
treefbc4c92c6318ce74bd269a67d2ab9cf6c9a6cd07 /src
parentc0e7ccd393d14cd08efbe36fd96cd786cc1f31d3 (diff)
downloademacs-c50f15d05a0f7da0a2e5a36e9bf8c626c5817d6b.tar.gz
emacs-c50f15d05a0f7da0a2e5a36e9bf8c626c5817d6b.zip
(Fcopy_file): New arg MUSTBENEW.
(Frename_file): Pass new arg to Fcopy_file.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/fileio.c b/src/fileio.c
index e4786974860..aaf75da4abb 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2388,7 +2388,7 @@ barf_or_query_if_file_exists (absname, querystring, interactive, statptr, quick)
2388 return; 2388 return;
2389} 2389}
2390 2390
2391DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 4, 2391DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 5,
2392 "fCopy file: \nGCopy %s to file: \np\nP", 2392 "fCopy file: \nGCopy %s to file: \np\nP",
2393 doc: /* Copy FILE to NEWNAME. Both args must be strings. 2393 doc: /* Copy FILE to NEWNAME. Both args must be strings.
2394If NEWNAME names a directory, copy FILE there. 2394If NEWNAME names a directory, copy FILE there.
@@ -2397,11 +2397,19 @@ unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.
2397A number as third arg means request confirmation if NEWNAME already exists. 2397A number as third arg means request confirmation if NEWNAME already exists.
2398This is what happens in interactive use with M-x. 2398This is what happens in interactive use with M-x.
2399Always sets the file modes of the output file to match the input file. 2399Always sets the file modes of the output file to match the input file.
2400
2400Fourth arg KEEP-TIME non-nil means give the output file the same 2401Fourth arg KEEP-TIME non-nil means give the output file the same
2401last-modified time as the old one. (This works on only some systems.) 2402last-modified time as the old one. (This works on only some systems.)
2403The optional fifth arg MUSTBENEW, if non-nil, insists on a check
2404 for an existing file with the same name. If MUSTBENEW is `excl',
2405 that means to get an error if the file already exists; never overwrite.
2406 If MUSTBENEW is neither nil nor `excl', that means ask for
2407 confirmation before overwriting, but do go ahead and overwrite the file
2408 if the user confirms.
2409
2402A prefix arg makes KEEP-TIME non-nil. */) 2410A prefix arg makes KEEP-TIME non-nil. */)
2403 (file, newname, ok_if_already_exists, keep_time) 2411 (file, newname, ok_if_already_exists, keep_time, mustbenew)
2404 Lisp_Object file, newname, ok_if_already_exists, keep_time; 2412 Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew;
2405{ 2413{
2406 int ifd, ofd, n; 2414 int ifd, ofd, n;
2407 char buf[16 * 1024]; 2415 char buf[16 * 1024];
@@ -2417,6 +2425,9 @@ A prefix arg makes KEEP-TIME non-nil. */)
2417 CHECK_STRING (file); 2425 CHECK_STRING (file);
2418 CHECK_STRING (newname); 2426 CHECK_STRING (newname);
2419 2427
2428 if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl))
2429 barf_or_query_if_file_exists (newname, "overwrite", 1, 0, 1);
2430
2420 if (!NILP (Ffile_directory_p (newname))) 2431 if (!NILP (Ffile_directory_p (newname)))
2421 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); 2432 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
2422 else 2433 else
@@ -2517,9 +2528,15 @@ A prefix arg makes KEEP-TIME non-nil. */)
2517#else 2528#else
2518#ifdef MSDOS 2529#ifdef MSDOS
2519 /* System's default file type was set to binary by _fmode in emacs.c. */ 2530 /* System's default file type was set to binary by _fmode in emacs.c. */
2520 ofd = creat (SDATA (encoded_newname), S_IREAD | S_IWRITE); 2531 ofd = emacs_open (SDATA (encoded_newname),
2521#else /* not MSDOS */ 2532 O_WRONLY | O_CREAT | buffer_file_type
2522 ofd = creat (SDATA (encoded_newname), 0666); 2533 | (EQ (mustbenew, Qexcl) ? O_EXCL : O_TRUNC),
2534 S_IREAD | S_IWRITE);
2535#else /* not MSDOS */
2536 ofd = emacs_open (SDATA (encoded_newname),
2537 O_WRONLY | O_TRUNC | O_CREAT
2538 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
2539 0666);
2523#endif /* not MSDOS */ 2540#endif /* not MSDOS */
2524#endif /* VMS */ 2541#endif /* VMS */
2525 if (ofd < 0) 2542 if (ofd < 0)
@@ -2749,7 +2766,8 @@ This is what happens in interactive use with M-x. */)
2749 Fcopy_file (file, newname, 2766 Fcopy_file (file, newname,
2750 /* We have already prompted if it was an integer, 2767 /* We have already prompted if it was an integer,
2751 so don't have copy-file prompt again. */ 2768 so don't have copy-file prompt again. */
2752 NILP (ok_if_already_exists) ? Qnil : Qt, Qt); 2769 NILP (ok_if_already_exists) ? Qnil : Qt,
2770 Qt, Qnil);
2753 Fdelete_file (file); 2771 Fdelete_file (file);
2754 } 2772 }
2755 else 2773 else