summaryrefslogtreecommitdiff
path: root/src/filelock.c
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2021-07-09 18:14:19 +0200
committerMichael Albinus <michael.albinus@gmx.de>2021-07-09 18:14:19 +0200
commit9ce6541ac9710933beca7f9944087fe4849d5ae9 (patch)
tree133344956b38933f504071bfa114fc712296f43c /src/filelock.c
parent2870a72d0d6675e189457394ac421bd8e5ab4561 (diff)
downloademacs-9ce6541ac9710933beca7f9944087fe4849d5ae9.tar.gz
Further cleanup for file locks
* doc/misc/tramp.texi (Top, Configuration): Adapt node name for file locks. (Auto-save File Lock and Backup): Rename node name and section title. Add file-lock to @cindex. Describe file locks. * lisp/dired.el (dired-trivial-filenames): Add lock files. (dired-font-lock-keywords): Move files suffixed with `completion-ignored-extensions' up. Add lock files to these checks. * lisp/net/tramp.el (tramp-get-lock-file, tramp-handle-unlock-file): Use `when-let' (tramp-lock-file-info-regexp): Rename from `tramp-lock-file-contents-regexp'. (tramp-handle-file-locked-p, tramp-handle-lock-file): Adapt callees. (tramp-handle-lock-file): Set file modes of lockname. * src/buffer.c (Frestore_buffer_modified_p): * src/fileio.c (write_region): * src/insdel.c (prepare_to_modify_buffer_1): Call Flock_file. * src/filelock.c (Qmake_lock_file_name): Declare symbol. (make_lock_file_name): Use it. Don't check Fboundp, it doesn't work for interned symbols. (lock_file): Return a Lisp_Object. Don't check create_lockfiles. Remove MSDOS version of the function. (Flock_file): Check create_lockfiles. (Flock_buffer): Call Flock_file. * src/lisp.h (lock_file): Remove. * test/lisp/shadowfile-tests.el (shadow-test08-shadow-todo) (shadow-test09-shadow-copy-files): Let-bind `create-lockfiles'. * test/lisp/net/tramp-tests.el (create-lockfiles): Don't set it globally. (tramp-test39-lock-file): Check also for `set-visited-file-name'.
Diffstat (limited to 'src/filelock.c')
-rw-r--r--src/filelock.c74
1 files changed, 34 insertions, 40 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 9f1968f07de..106633f5846 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -622,10 +622,7 @@ lock_if_free (lock_info_type *clasher, char *lfname)
static Lisp_Object
make_lock_file_name (Lisp_Object fn)
{
- Lisp_Object func = intern ("make-lock-file-name");
- if (NILP (Fboundp (func)))
- return Qnil;
- return call1 (func, Fexpand_file_name (fn, Qnil));
+ return call1 (Qmake_lock_file_name, Fexpand_file_name (fn, Qnil));
}
/* lock_file locks file FN,
@@ -646,7 +643,7 @@ make_lock_file_name (Lisp_Object fn)
This function can signal an error, or return t meaning
take away the lock, or return nil meaning ignore the lock. */
-void
+static Lisp_Object
lock_file (Lisp_Object fn)
{
lock_info_type lock_info;
@@ -655,7 +652,7 @@ lock_file (Lisp_Object fn)
Uncompressing wtmp files uses call-process, which does not work
in an uninitialized Emacs. */
if (will_dump_p ())
- return;
+ return Qnil;
/* If the file name has special constructs in it,
call the corresponding file name handler. */
@@ -663,13 +660,12 @@ lock_file (Lisp_Object fn)
handler = Ffind_file_name_handler (fn, Qlock_file);
if (!NILP (handler))
{
- call2 (handler, Qlock_file, fn);
- return;
+ return call2 (handler, Qlock_file, fn);
}
Lisp_Object lock_filename = make_lock_file_name (fn);
if (NILP (lock_filename))
- return;
+ return Qnil;
char *lfname = SSDATA (ENCODE_FILE (lock_filename));
/* See if this file is visited and has changed on disk since it was
@@ -678,32 +674,29 @@ lock_file (Lisp_Object fn)
if (!NILP (subject_buf)
&& NILP (Fverify_visited_file_modtime (subject_buf))
&& !NILP (Ffile_exists_p (lock_filename))
- && !(create_lockfiles && current_lock_owner (NULL, lfname) == -2))
+ && current_lock_owner (NULL, lfname) != -2)
call1 (intern ("userlock--ask-user-about-supersession-threat"), fn);
- /* Don't do locking if the user has opted out. */
- if (create_lockfiles)
+ /* 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)
{
- /* 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);
- }
+ /* 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;
}
static Lisp_Object
@@ -732,12 +725,6 @@ unlock_file_handle_error (Lisp_Object err)
return Qnil;
}
-#else /* MSDOS */
-void
-lock_file (Lisp_Object fn)
-{
-}
-
#endif /* MSDOS */
void
@@ -760,8 +747,14 @@ DEFUN ("lock-file", Flock_file, Slock_file, 1, 1, 0,
If the option `create-lockfiles' is nil, this does nothing. */)
(Lisp_Object file)
{
- CHECK_STRING (file);
- lock_file (file);
+#ifndef MSDOS
+ /* Don't do locking if the user has opted out. */
+ if (create_lockfiles)
+ {
+ CHECK_STRING (file);
+ lock_file (file);
+ }
+#endif /* MSDOS */
return Qnil;
}
@@ -805,7 +798,7 @@ If the option `create-lockfiles' is nil, this does nothing. */)
CHECK_STRING (file);
if (SAVE_MODIFF < MODIFF
&& !NILP (file))
- lock_file (file);
+ Flock_file (file);
return Qnil;
}
@@ -892,6 +885,7 @@ Info node `(emacs)Interlocking'. */);
DEFSYM (Qlock_file, "lock-file");
DEFSYM (Qunlock_file, "unlock-file");
DEFSYM (Qfile_locked_p, "file-locked-p");
+ DEFSYM (Qmake_lock_file_name, "make-lock-file-name");
defsubr (&Slock_file);
defsubr (&Sunlock_file);