summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2022-01-29 11:45:38 +0100
committerMichael Albinus <michael.albinus@gmx.de>2022-01-29 11:45:38 +0100
commitddba3c3dba539155e1b3835217a9e38bdf431185 (patch)
treee82a4f38ad52845997a2ae51f3c856ba13c4a0a3
parent3dd47bde7a87bef332bd53f3e73c8d2bc64910c8 (diff)
downloademacs-ddba3c3dba539155e1b3835217a9e38bdf431185.tar.gz
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)
-rw-r--r--src/filelock.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 892a451e8cb..e1e2cc1b23e 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;
}