mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-22 07:09:54 +00:00
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.
This commit is contained in:
parent
274e71f5cc
commit
a6a92e3ac5
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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."
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
16
src/fileio.c
16
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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user