emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 5656492 1/2: When creating a link, ask only if EEXI


From: Paul Eggert
Subject: [Emacs-diffs] master 5656492 1/2: When creating a link, ask only if EEXIST
Date: Wed, 2 Aug 2017 04:59:37 -0400 (EDT)

branch: master
commit 5656492d04aa1a82747ff167d8063bbd7950597e
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    When creating a link, ask only if EEXIST
    
    * src/fileio.c (Fadd_name_to_file, Fmake_symbolic_link):
    Ask the user (and unlink and retry) only if link creation fails
    with errno == EEXIST.  This avoids the need to ask the user for
    permission to do an operation that will fail anyway.
---
 src/fileio.c | 58 +++++++++++++++++++++++++++-------------------------------
 1 file changed, 27 insertions(+), 31 deletions(-)

diff --git a/src/fileio.c b/src/fileio.c
index 7531214..96c5639 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2425,19 +2425,21 @@ This is what happens in interactive use with M-x.  */)
   encoded_file = ENCODE_FILE (file);
   encoded_newname = ENCODE_FILE (newname);
 
-  if (NILP (ok_if_already_exists)
-      || INTEGERP (ok_if_already_exists))
-    barf_or_query_if_file_exists (newname, false, "make it a new name",
-                                 INTEGERP (ok_if_already_exists), false);
+  if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) == 0)
+    return Qnil;
 
-  unlink (SSDATA (newname));
-  if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) < 0)
+  if (errno == EEXIST)
     {
-      int link_errno = errno;
-      report_file_errno ("Adding new name", list2 (file, newname), link_errno);
+      if (NILP (ok_if_already_exists)
+         || INTEGERP (ok_if_already_exists))
+       barf_or_query_if_file_exists (newname, true, "make it a new name",
+                                     INTEGERP (ok_if_already_exists), false);
+      unlink (SSDATA (newname));
+      if (link (SSDATA (encoded_file), SSDATA (encoded_newname)) == 0)
+       return Qnil;
     }
 
-  return Qnil;
+  report_file_error ("Adding new name", list2 (file, newname));
 }
 
 DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3,
@@ -2484,31 +2486,25 @@ This happens for interactive use with M-x.  */)
   encoded_target = ENCODE_FILE (target);
   encoded_linkname = ENCODE_FILE (linkname);
 
-  if (NILP (ok_if_already_exists)
-      || INTEGERP (ok_if_already_exists))
-    barf_or_query_if_file_exists (linkname, false, "make it a link",
-                                 INTEGERP (ok_if_already_exists), false);
-  if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) < 0)
-    {
-      /* If we didn't complain already, silently delete existing file.  */
-      int symlink_errno;
-      if (errno == EEXIST)
-       {
-         unlink (SSDATA (encoded_linkname));
-         if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname))
-             >= 0)
-           return Qnil;
-       }
-      if (errno == ENOSYS)
-       xsignal1 (Qfile_error,
-                 build_string ("Symbolic links are not supported"));
+  if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) == 0)
+    return Qnil;
 
-      symlink_errno = errno;
-      report_file_errno ("Making symbolic link", list2 (target, linkname),
-                        symlink_errno);
+  if (errno == ENOSYS)
+    xsignal1 (Qfile_error,
+             build_string ("Symbolic links are not supported"));
+
+  if (errno == EEXIST)
+    {
+      if (NILP (ok_if_already_exists)
+         || INTEGERP (ok_if_already_exists))
+       barf_or_query_if_file_exists (linkname, true, "make it a link",
+                                     INTEGERP (ok_if_already_exists), false);
+      unlink (SSDATA (encoded_linkname));
+      if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) == 0)
+       return Qnil;
     }
 
-  return Qnil;
+  report_file_error ("Making symbolic link", list2 (target, linkname));
 }
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]