emacs-diffs
[Top][All Lists]
Advanced

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

emacs-28 ddba3c3dba: Fix error in filelock.c


From: Michael Albinus
Subject: emacs-28 ddba3c3dba: Fix error in filelock.c
Date: Sat, 29 Jan 2022 05:45:46 -0500 (EST)

branch: emacs-28
commit ddba3c3dba539155e1b3835217a9e38bdf431185
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Fix error in filelock.c
    
    * src/filelock.c (lock_file): Move call of file name handler to
    `Flock_file'.  Determine lock_filename only in case
    create_lockfiles is non-nil.  Adapt the rest of the function accordingly.
    (Flock_file): Do not check for create_lockfiles.  Call file name
    handler if appropriate.  (Bug#53207)
---
 src/filelock.c | 74 +++++++++++++++++++++++++++++++---------------------------
 1 file changed, 39 insertions(+), 35 deletions(-)

diff --git a/src/filelock.c b/src/filelock.c
index 892a451e8c..e1e2cc1b23 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -646,6 +646,7 @@ make_lock_file_name (Lisp_Object fn)
 static Lisp_Object
 lock_file (Lisp_Object fn)
 {
+  char *lfname = NULL;
   lock_info_type lock_info;
 
   /* Don't do locking while dumping Emacs.
@@ -654,47 +655,46 @@ lock_file (Lisp_Object fn)
   if (will_dump_p ())
     return Qnil;
 
-  /* If the file name has special constructs in it,
-     call the corresponding file name handler.  */
-  Lisp_Object handler;
-  handler = Ffind_file_name_handler (fn, Qlock_file);
-  if (!NILP (handler))
+  if (create_lockfiles)
     {
-      return call2 (handler, Qlock_file, fn);
+      /* Create the name of the lock-file for file fn */
+      Lisp_Object lock_filename = make_lock_file_name (fn);
+      if (NILP (lock_filename))
+       return Qnil;
+      lfname = SSDATA (ENCODE_FILE (lock_filename));
     }
 
-  Lisp_Object lock_filename = make_lock_file_name (fn);
-  if (NILP (lock_filename))
-    return Qnil;
-  char *lfname = SSDATA (ENCODE_FILE (lock_filename));
-
   /* See if this file is visited and has changed on disk since it was
      visited.  */
   Lisp_Object subject_buf = get_truename_buffer (fn);
   if (!NILP (subject_buf)
       && NILP (Fverify_visited_file_modtime (subject_buf))
       && !NILP (Ffile_exists_p (fn))
-      && current_lock_owner (NULL, lfname) != -2)
+      && !(lfname && current_lock_owner (NULL, lfname) == -2))
     call1 (intern ("userlock--ask-user-about-supersession-threat"), fn);
 
-  /* Try to lock the lock.  FIXME: This ignores errors when
-     lock_if_free returns a positive errno value.  */
-  if (lock_if_free (&lock_info, lfname) < 0)
+  /* Don't do locking if the user has opted out.  */
+  if (lfname)
     {
-      /* Someone else has the lock.  Consider breaking it.  */
-      Lisp_Object attack;
-      char *dot = lock_info.dot;
-      ptrdiff_t pidlen = lock_info.colon - (dot + 1);
-      static char const replacement[] = " (pid ";
-      int replacementlen = sizeof replacement - 1;
-      memmove (dot + replacementlen, dot + 1, pidlen);
-      strcpy (dot + replacementlen + pidlen, ")");
-      memcpy (dot, replacement, replacementlen);
-      attack = call2 (intern ("ask-user-about-lock"), fn,
-                     build_string (lock_info.user));
-      /* Take the lock if the user said so.  */
-      if (!NILP (attack))
-       lock_file_1 (lfname, 1);
+      /* Try to lock the lock.  FIXME: This ignores errors when
+        lock_if_free returns a positive errno value.  */
+      if (lock_if_free (&lock_info, lfname) < 0)
+       {
+         /* Someone else has the lock.  Consider breaking it.  */
+         Lisp_Object attack;
+         char *dot = lock_info.dot;
+         ptrdiff_t pidlen = lock_info.colon - (dot + 1);
+         static char const replacement[] = " (pid ";
+         int replacementlen = sizeof replacement - 1;
+         memmove (dot + replacementlen, dot + 1, pidlen);
+         strcpy (dot + replacementlen + pidlen, ")");
+         memcpy (dot, replacement, replacementlen);
+         attack = call2 (intern ("ask-user-about-lock"), fn,
+                         build_string (lock_info.user));
+         /* Take the lock if the user said so.  */
+         if (!NILP (attack))
+           lock_file_1 (lfname, 1);
+       }
     }
   return Qnil;
 }
@@ -748,12 +748,16 @@ If the option `create-lockfiles' is nil, this does 
nothing.  */)
   (Lisp_Object file)
 {
 #ifndef MSDOS
-  /* Don't do locking if the user has opted out.  */
-  if (create_lockfiles)
-    {
-      CHECK_STRING (file);
-      lock_file (file);
-    }
+  CHECK_STRING (file);
+
+  /* If the file name has special constructs in it,
+     call the corresponding file name handler.  */
+  Lisp_Object handler;
+  handler = Ffind_file_name_handler (file, Qlock_file);
+  if (!NILP (handler))
+    return call2 (handler, Qlock_file, file);
+
+  lock_file (file);
 #endif /* MSDOS */
   return Qnil;
 }



reply via email to

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