diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileio.c | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/fileio.c b/src/fileio.c index 7531214fe45..96c5639a096 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -2425,19 +2425,21 @@ This is what happens in interactive use with M-x. */) | |||
| 2425 | encoded_file = ENCODE_FILE (file); | 2425 | encoded_file = ENCODE_FILE (file); |
| 2426 | encoded_newname = ENCODE_FILE (newname); | 2426 | encoded_newname = ENCODE_FILE (newname); |
| 2427 | 2427 | ||
| 2428 | if (NILP (ok_if_already_exists) | 2428 | if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) == 0) |
| 2429 | || INTEGERP (ok_if_already_exists)) | 2429 | return Qnil; |
| 2430 | barf_or_query_if_file_exists (newname, false, "make it a new name", | ||
| 2431 | INTEGERP (ok_if_already_exists), false); | ||
| 2432 | 2430 | ||
| 2433 | unlink (SSDATA (newname)); | 2431 | if (errno == EEXIST) |
| 2434 | if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) < 0) | ||
| 2435 | { | 2432 | { |
| 2436 | int link_errno = errno; | 2433 | if (NILP (ok_if_already_exists) |
| 2437 | report_file_errno ("Adding new name", list2 (file, newname), link_errno); | 2434 | || INTEGERP (ok_if_already_exists)) |
| 2435 | barf_or_query_if_file_exists (newname, true, "make it a new name", | ||
| 2436 | INTEGERP (ok_if_already_exists), false); | ||
| 2437 | unlink (SSDATA (newname)); | ||
| 2438 | if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) == 0) | ||
| 2439 | return Qnil; | ||
| 2438 | } | 2440 | } |
| 2439 | 2441 | ||
| 2440 | return Qnil; | 2442 | report_file_error ("Adding new name", list2 (file, newname)); |
| 2441 | } | 2443 | } |
| 2442 | 2444 | ||
| 2443 | DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3, | 2445 | DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3, |
| @@ -2484,31 +2486,25 @@ This happens for interactive use with M-x. */) | |||
| 2484 | encoded_target = ENCODE_FILE (target); | 2486 | encoded_target = ENCODE_FILE (target); |
| 2485 | encoded_linkname = ENCODE_FILE (linkname); | 2487 | encoded_linkname = ENCODE_FILE (linkname); |
| 2486 | 2488 | ||
| 2487 | if (NILP (ok_if_already_exists) | 2489 | if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) == 0) |
| 2488 | || INTEGERP (ok_if_already_exists)) | 2490 | return Qnil; |
| 2489 | barf_or_query_if_file_exists (linkname, false, "make it a link", | ||
| 2490 | INTEGERP (ok_if_already_exists), false); | ||
| 2491 | if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) < 0) | ||
| 2492 | { | ||
| 2493 | /* If we didn't complain already, silently delete existing file. */ | ||
| 2494 | int symlink_errno; | ||
| 2495 | if (errno == EEXIST) | ||
| 2496 | { | ||
| 2497 | unlink (SSDATA (encoded_linkname)); | ||
| 2498 | if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) | ||
| 2499 | >= 0) | ||
| 2500 | return Qnil; | ||
| 2501 | } | ||
| 2502 | if (errno == ENOSYS) | ||
| 2503 | xsignal1 (Qfile_error, | ||
| 2504 | build_string ("Symbolic links are not supported")); | ||
| 2505 | 2491 | ||
| 2506 | symlink_errno = errno; | 2492 | if (errno == ENOSYS) |
| 2507 | report_file_errno ("Making symbolic link", list2 (target, linkname), | 2493 | xsignal1 (Qfile_error, |
| 2508 | symlink_errno); | 2494 | build_string ("Symbolic links are not supported")); |
| 2495 | |||
| 2496 | if (errno == EEXIST) | ||
| 2497 | { | ||
| 2498 | if (NILP (ok_if_already_exists) | ||
| 2499 | || INTEGERP (ok_if_already_exists)) | ||
| 2500 | barf_or_query_if_file_exists (linkname, true, "make it a link", | ||
| 2501 | INTEGERP (ok_if_already_exists), false); | ||
| 2502 | unlink (SSDATA (encoded_linkname)); | ||
| 2503 | if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) == 0) | ||
| 2504 | return Qnil; | ||
| 2509 | } | 2505 | } |
| 2510 | 2506 | ||
| 2511 | return Qnil; | 2507 | report_file_error ("Making symbolic link", list2 (target, linkname)); |
| 2512 | } | 2508 | } |
| 2513 | 2509 | ||
| 2514 | 2510 | ||