[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a6a92e3: Code cleanup wrt file locks
From: |
Michael Albinus |
Subject: |
master a6a92e3: Code cleanup wrt file locks |
Date: |
Thu, 8 Jul 2021 15:13:48 -0400 (EDT) |
branch: master
commit a6a92e3ac55b4a07f3b91dffecc28a89c2b5dbf2
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>
Code cleanup wrt file locks
* lisp/files.el (make-lock-file-name): Fix docstring.
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist):
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add `make-lock-file-name'.
* lisp/net/tramp.el (tramp-file-name-for-operation):
Add `make-lock-file-name'.
(tramp-handle-unlock-file): Call `userlock--handle-unlock-error'
in case of error.
* src/buffer.c (Frestore_buffer_modified_p):
* src/editfns.c (Freplace_buffer_contents):
* src/fileio.c (Finsert_file_contents, write_region): Call Funlock_file.
* src/filelock.c (unlock_file): Rename from unlock_file_body.
Remove the other declarations of unlock_file. Move file name
handler check to ...
(Funlock_file): ... here. Adapt argument numbers. Call
unlock_file wrapped by internal_condition_case.
(Flock_file): Adapt argument numbers.
(unlock_all_files, Funlock_buffer, unlock_buffer): Call Funlock_file.
* src/lisp.h (unlock_file): Remove.
---
lisp/files.el | 2 +-
lisp/net/tramp-adb.el | 1 +
lisp/net/tramp-archive.el | 1 +
lisp/net/tramp-crypt.el | 1 +
lisp/net/tramp-gvfs.el | 1 +
lisp/net/tramp-rclone.el | 1 +
lisp/net/tramp-sh.el | 1 +
lisp/net/tramp-smb.el | 1 +
lisp/net/tramp-sshfs.el | 1 +
lisp/net/tramp-sudoedit.el | 1 +
lisp/net/tramp.el | 7 +++---
lisp/userlock.el | 2 +-
src/buffer.c | 2 +-
src/editfns.c | 2 +-
src/fileio.c | 16 ++++++-------
src/filelock.c | 58 ++++++++++++++++++++--------------------------
src/lisp.h | 1 -
17 files changed, 50 insertions(+), 49 deletions(-)
diff --git a/lisp/files.el b/lisp/files.el
index da8598f..0dfcab8 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6795,7 +6795,7 @@ the resulting file name, and SUFFIX is appended."
(defun make-lock-file-name (filename)
"Make a lock file name for FILENAME.
-By default, this just prepends \".*\" to the non-directory part
+By default, this just prepends \".#\" to the non-directory part
of FILENAME, but the transforms in `lock-file-name-transforms'
are done first."
(let ((handler (find-file-name-handler filename 'make-lock-file-name)))
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 2bd1367..788548b 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -164,6 +164,7 @@ It is used for TCP/IP devices."
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-adb-handle-make-directory)
(make-directory-internal . ignore)
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-adb-handle-make-process)
(make-symbolic-link . tramp-handle-make-symbolic-link)
diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el
index a6f479b..67798e8 100644
--- a/lisp/net/tramp-archive.el
+++ b/lisp/net/tramp-archive.el
@@ -267,6 +267,7 @@ It must be supported by libarchive(3).")
(make-auto-save-file-name . ignore)
(make-directory . tramp-archive-handle-not-implemented)
(make-directory-internal . tramp-archive-handle-not-implemented)
+ (make-lock-file-name . ignore)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-archive-handle-not-implemented)
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el
index 31988bc..1b77fea 100644
--- a/lisp/net/tramp-crypt.el
+++ b/lisp/net/tramp-crypt.el
@@ -213,6 +213,7 @@ If NAME doesn't belong to a crypted remote directory, retun
nil."
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-crypt-handle-make-directory)
(make-directory-internal . ignore)
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index e784ea8..04de5de 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -805,6 +805,7 @@ It has been changed in GVFS 1.14.")
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-gvfs-handle-make-directory)
(make-directory-internal . ignore)
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el
index 6c710dd..473fa8a 100644
--- a/lisp/net/tramp-rclone.el
+++ b/lisp/net/tramp-rclone.el
@@ -127,6 +127,7 @@
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-fuse-handle-make-directory)
(make-directory-internal . ignore)
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index c65800b..404e9af 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -993,6 +993,7 @@ Format specifiers \"%s\" are replaced before the script is
used.")
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-sh-handle-make-directory)
;; `make-directory-internal' performed by default handler.
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-sh-handle-make-process)
(make-symbolic-link . tramp-sh-handle-make-symbolic-link)
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 01192db..87f6239 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -278,6 +278,7 @@ See `tramp-actions-before-shell' for more info.")
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-smb-handle-make-directory)
(make-directory-internal . tramp-smb-handle-make-directory-internal)
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-smb-handle-make-symbolic-link)
diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el
index babd770..3a3703b 100644
--- a/lisp/net/tramp-sshfs.el
+++ b/lisp/net/tramp-sshfs.el
@@ -127,6 +127,7 @@
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-fuse-handle-make-directory)
(make-directory-internal . ignore)
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-handle-make-process)
(make-symbolic-link . tramp-handle-make-symbolic-link)
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index aa6f85e..d68a5c1 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -120,6 +120,7 @@ See `tramp-actions-before-shell' for more info.")
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-sudoedit-handle-make-directory)
(make-directory-internal . ignore)
+ ;; `make-lock-file-name' performed by default handler.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-sudoedit-handle-make-symbolic-link)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index e9e0826..7578d6f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2456,7 +2456,7 @@ Must be handled by the callers."
;; Emacs 27+ only.
file-system-info
;; Emacs 28+ only.
- file-locked-p lock-file unlock-file
+ file-locked-p lock-file make-lock-file-name unlock-file
;; Tramp internal magic file name function.
tramp-set-file-uid-gid))
(if (file-name-absolute-p (nth 0 args))
@@ -3881,8 +3881,9 @@ Return nil when there is no lockfile"
(defun tramp-handle-unlock-file (file)
"Like `unlock-file' for Tramp files."
- (ignore-errors
- (delete-file (tramp-compat-make-lock-file-name file))))
+ (condition-case err
+ (delete-file (tramp-compat-make-lock-file-name file))
+ (error (userlock--handle-unlock-error err))))
(defun tramp-handle-load (file &optional noerror nomessage nosuffix
must-suffix)
"Like `load' for Tramp files."
diff --git a/lisp/userlock.el b/lisp/userlock.el
index 4a75815..38aaf6a 100644
--- a/lisp/userlock.el
+++ b/lisp/userlock.el
@@ -230,7 +230,7 @@ to get the latest version of the file, then make the change
again."
(display-warning
'(unlock-file)
;; There is no need to explain that this is an unlock error because
- ;; ERR is a `file-error' condition, which explains this.
+ ;; ERROR is a `file-error' condition, which explains this.
(message "%s, ignored" (error-message-string error))
:warning))
diff --git a/src/buffer.c b/src/buffer.c
index 565577e..3cd47fe 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1451,7 +1451,7 @@ state of the current buffer. Use with care. */)
if (!already && !NILP (flag))
lock_file (fn);
else if (already && NILP (flag))
- unlock_file (fn);
+ Funlock_file (fn);
}
}
diff --git a/src/editfns.c b/src/editfns.c
index aa0f46f..8ab17eb 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2137,7 +2137,7 @@ nil. */)
the file now. */
if (SAVE_MODIFF == MODIFF
&& STRINGP (BVAR (a, file_truename)))
- unlock_file (BVAR (a, file_truename));
+ Funlock_file (BVAR (a, file_truename));
}
return Qt;
diff --git a/src/fileio.c b/src/fileio.c
index c0d1a50..30e6caf 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4544,7 +4544,7 @@ by calling `format-decode', which see. */)
if (inserted == 0)
{
if (we_locked_file)
- unlock_file (BVAR (current_buffer, file_truename));
+ Funlock_file (BVAR (current_buffer, file_truename));
Vdeactivate_mark = old_Vdeactivate_mark;
}
else
@@ -4706,8 +4706,8 @@ by calling `format-decode', which see. */)
if (NILP (handler))
{
if (!NILP (BVAR (current_buffer, file_truename)))
- unlock_file (BVAR (current_buffer, file_truename));
- unlock_file (filename);
+ Funlock_file (BVAR (current_buffer, file_truename));
+ Funlock_file (filename);
}
if (not_regular)
xsignal2 (Qfile_error,
@@ -5193,7 +5193,7 @@ write_region (Lisp_Object start, Lisp_Object end,
Lisp_Object filename,
{
int open_errno = errno;
if (file_locked)
- unlock_file (lockname);
+ Funlock_file (lockname);
report_file_errno ("Opening output file", filename, open_errno);
}
@@ -5208,7 +5208,7 @@ write_region (Lisp_Object start, Lisp_Object end,
Lisp_Object filename,
{
int lseek_errno = errno;
if (file_locked)
- unlock_file (lockname);
+ Funlock_file (lockname);
report_file_errno ("Lseek error", filename, lseek_errno);
}
}
@@ -5345,7 +5345,7 @@ write_region (Lisp_Object start, Lisp_Object end,
Lisp_Object filename,
unbind_to (count, Qnil);
if (file_locked)
- unlock_file (lockname);
+ Funlock_file (lockname);
/* Do this before reporting IO error
to avoid a "file has changed on disk" warning on
@@ -5370,14 +5370,14 @@ write_region (Lisp_Object start, Lisp_Object end,
Lisp_Object filename,
bset_filename (current_buffer, visit_file);
update_mode_lines = 14;
if (auto_saving_into_visited_file)
- unlock_file (lockname);
+ Funlock_file (lockname);
}
else if (quietly)
{
if (auto_saving_into_visited_file)
{
SAVE_MODIFF = MODIFF;
- unlock_file (lockname);
+ Funlock_file (lockname);
}
return Qnil;
diff --git a/src/filelock.c b/src/filelock.c
index 20916ac..9f1968f 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -657,6 +657,8 @@ lock_file (Lisp_Object fn)
if (will_dump_p ())
return;
+ /* 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))
@@ -705,20 +707,10 @@ lock_file (Lisp_Object fn)
}
static Lisp_Object
-unlock_file_body (Lisp_Object fn)
+unlock_file (Lisp_Object fn)
{
char *lfname;
- /* If the file name has special constructs in it,
- call the corresponding file name handler. */
- Lisp_Object handler;
- handler = Ffind_file_name_handler (fn, Qunlock_file);
- if (!NILP (handler))
- {
- call2 (handler, Qunlock_file, fn);
- return Qnil;
- }
-
Lisp_Object lock_filename = make_lock_file_name (fn);
if (NILP (lock_filename))
return Qnil;
@@ -740,26 +732,12 @@ unlock_file_handle_error (Lisp_Object err)
return Qnil;
}
-void
-unlock_file (Lisp_Object fn)
-{
- internal_condition_case_1 (unlock_file_body,
- fn,
- list1(Qfile_error),
- unlock_file_handle_error);
-}
-
#else /* MSDOS */
void
lock_file (Lisp_Object fn)
{
}
-void
-unlock_file (Lisp_Object fn)
-{
-}
-
#endif /* MSDOS */
void
@@ -773,12 +751,11 @@ unlock_all_files (void)
b = XBUFFER (buf);
if (STRINGP (BVAR (b, file_truename))
&& BUF_SAVE_MODIFF (b) < BUF_MODIFF (b))
- unlock_file (BVAR (b, file_truename));
+ Funlock_file (BVAR (b, file_truename));
}
}
-DEFUN ("lock-file", Flock_file, Slock_file,
- 0, 1, 0,
+DEFUN ("lock-file", Flock_file, Slock_file, 1, 1, 0,
doc: /* Lock FILE.
If the option `create-lockfiles' is nil, this does nothing. */)
(Lisp_Object file)
@@ -788,13 +765,28 @@ If the option `create-lockfiles' is nil, this does
nothing. */)
return Qnil;
}
-DEFUN ("unlock-file", Funlock_file, Sunlock_file,
- 0, 1, 0,
+DEFUN ("unlock-file", Funlock_file, Sunlock_file, 1, 1, 0,
doc: /* Unlock FILE. */)
(Lisp_Object file)
{
+#ifndef MSDOS
CHECK_STRING (file);
- unlock_file (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, Qunlock_file);
+ if (!NILP (handler))
+ {
+ call2 (handler, Qunlock_file, file);
+ return Qnil;
+ }
+
+ internal_condition_case_1 (unlock_file,
+ file,
+ list1 (Qfile_error),
+ unlock_file_handle_error);
+#endif /* MSDOS */
return Qnil;
}
@@ -829,7 +821,7 @@ error did not occur. */)
{
if (SAVE_MODIFF < MODIFF
&& STRINGP (BVAR (current_buffer, file_truename)))
- unlock_file (BVAR (current_buffer, file_truename));
+ Funlock_file (BVAR (current_buffer, file_truename));
return Qnil;
}
@@ -840,7 +832,7 @@ unlock_buffer (struct buffer *buffer)
{
if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer)
&& STRINGP (BVAR (buffer, file_truename)))
- unlock_file (BVAR (buffer, file_truename));
+ Funlock_file (BVAR (buffer, file_truename));
}
DEFUN ("file-locked-p", Ffile_locked_p, Sfile_locked_p, 1, 1, 0,
diff --git a/src/lisp.h b/src/lisp.h
index 4fb8923..ce4b80a 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4622,7 +4622,6 @@ extern void syms_of_sysdep (void);
/* Defined in filelock.c. */
extern void lock_file (Lisp_Object);
-extern void unlock_file (Lisp_Object);
extern void unlock_all_files (void);
extern void unlock_buffer (struct buffer *);
extern void syms_of_filelock (void);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master a6a92e3: Code cleanup wrt file locks,
Michael Albinus <=