diff options
| author | Michael Albinus | 2021-07-08 21:13:40 +0200 |
|---|---|---|
| committer | Michael Albinus | 2021-07-08 21:13:40 +0200 |
| commit | a6a92e3ac55b4a07f3b91dffecc28a89c2b5dbf2 (patch) | |
| tree | d2820313d3076143011ab5c4fbe3b42282465baf /src | |
| parent | 274e71f5cc33834a08e7bd24418553198cb01f34 (diff) | |
| download | emacs-a6a92e3ac55b4a07f3b91dffecc28a89c2b5dbf2.tar.gz emacs-a6a92e3ac55b4a07f3b91dffecc28a89c2b5dbf2.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.c | 2 | ||||
| -rw-r--r-- | src/editfns.c | 2 | ||||
| -rw-r--r-- | src/fileio.c | 16 | ||||
| -rw-r--r-- | src/filelock.c | 58 | ||||
| -rw-r--r-- | src/lisp.h | 1 |
5 files changed, 35 insertions, 44 deletions
diff --git a/src/buffer.c b/src/buffer.c index 565577e75ae..3cd47fede36 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1451,7 +1451,7 @@ state of the current buffer. Use with care. */) | |||
| 1451 | if (!already && !NILP (flag)) | 1451 | if (!already && !NILP (flag)) |
| 1452 | lock_file (fn); | 1452 | lock_file (fn); |
| 1453 | else if (already && NILP (flag)) | 1453 | else if (already && NILP (flag)) |
| 1454 | unlock_file (fn); | 1454 | Funlock_file (fn); |
| 1455 | } | 1455 | } |
| 1456 | } | 1456 | } |
| 1457 | 1457 | ||
diff --git a/src/editfns.c b/src/editfns.c index aa0f46fea04..8ab17ebc9f9 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2137,7 +2137,7 @@ nil. */) | |||
| 2137 | the file now. */ | 2137 | the file now. */ |
| 2138 | if (SAVE_MODIFF == MODIFF | 2138 | if (SAVE_MODIFF == MODIFF |
| 2139 | && STRINGP (BVAR (a, file_truename))) | 2139 | && STRINGP (BVAR (a, file_truename))) |
| 2140 | unlock_file (BVAR (a, file_truename)); | 2140 | Funlock_file (BVAR (a, file_truename)); |
| 2141 | } | 2141 | } |
| 2142 | 2142 | ||
| 2143 | return Qt; | 2143 | return Qt; |
diff --git a/src/fileio.c b/src/fileio.c index c0d1a5084a0..30e6caf7ea5 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -4544,7 +4544,7 @@ by calling `format-decode', which see. */) | |||
| 4544 | if (inserted == 0) | 4544 | if (inserted == 0) |
| 4545 | { | 4545 | { |
| 4546 | if (we_locked_file) | 4546 | if (we_locked_file) |
| 4547 | unlock_file (BVAR (current_buffer, file_truename)); | 4547 | Funlock_file (BVAR (current_buffer, file_truename)); |
| 4548 | Vdeactivate_mark = old_Vdeactivate_mark; | 4548 | Vdeactivate_mark = old_Vdeactivate_mark; |
| 4549 | } | 4549 | } |
| 4550 | else | 4550 | else |
| @@ -4706,8 +4706,8 @@ by calling `format-decode', which see. */) | |||
| 4706 | if (NILP (handler)) | 4706 | if (NILP (handler)) |
| 4707 | { | 4707 | { |
| 4708 | if (!NILP (BVAR (current_buffer, file_truename))) | 4708 | if (!NILP (BVAR (current_buffer, file_truename))) |
| 4709 | unlock_file (BVAR (current_buffer, file_truename)); | 4709 | Funlock_file (BVAR (current_buffer, file_truename)); |
| 4710 | unlock_file (filename); | 4710 | Funlock_file (filename); |
| 4711 | } | 4711 | } |
| 4712 | if (not_regular) | 4712 | if (not_regular) |
| 4713 | xsignal2 (Qfile_error, | 4713 | xsignal2 (Qfile_error, |
| @@ -5193,7 +5193,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, | |||
| 5193 | { | 5193 | { |
| 5194 | int open_errno = errno; | 5194 | int open_errno = errno; |
| 5195 | if (file_locked) | 5195 | if (file_locked) |
| 5196 | unlock_file (lockname); | 5196 | Funlock_file (lockname); |
| 5197 | report_file_errno ("Opening output file", filename, open_errno); | 5197 | report_file_errno ("Opening output file", filename, open_errno); |
| 5198 | } | 5198 | } |
| 5199 | 5199 | ||
| @@ -5208,7 +5208,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, | |||
| 5208 | { | 5208 | { |
| 5209 | int lseek_errno = errno; | 5209 | int lseek_errno = errno; |
| 5210 | if (file_locked) | 5210 | if (file_locked) |
| 5211 | unlock_file (lockname); | 5211 | Funlock_file (lockname); |
| 5212 | report_file_errno ("Lseek error", filename, lseek_errno); | 5212 | report_file_errno ("Lseek error", filename, lseek_errno); |
| 5213 | } | 5213 | } |
| 5214 | } | 5214 | } |
| @@ -5345,7 +5345,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, | |||
| 5345 | unbind_to (count, Qnil); | 5345 | unbind_to (count, Qnil); |
| 5346 | 5346 | ||
| 5347 | if (file_locked) | 5347 | if (file_locked) |
| 5348 | unlock_file (lockname); | 5348 | Funlock_file (lockname); |
| 5349 | 5349 | ||
| 5350 | /* Do this before reporting IO error | 5350 | /* Do this before reporting IO error |
| 5351 | to avoid a "file has changed on disk" warning on | 5351 | 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, | |||
| 5370 | bset_filename (current_buffer, visit_file); | 5370 | bset_filename (current_buffer, visit_file); |
| 5371 | update_mode_lines = 14; | 5371 | update_mode_lines = 14; |
| 5372 | if (auto_saving_into_visited_file) | 5372 | if (auto_saving_into_visited_file) |
| 5373 | unlock_file (lockname); | 5373 | Funlock_file (lockname); |
| 5374 | } | 5374 | } |
| 5375 | else if (quietly) | 5375 | else if (quietly) |
| 5376 | { | 5376 | { |
| 5377 | if (auto_saving_into_visited_file) | 5377 | if (auto_saving_into_visited_file) |
| 5378 | { | 5378 | { |
| 5379 | SAVE_MODIFF = MODIFF; | 5379 | SAVE_MODIFF = MODIFF; |
| 5380 | unlock_file (lockname); | 5380 | Funlock_file (lockname); |
| 5381 | } | 5381 | } |
| 5382 | 5382 | ||
| 5383 | return Qnil; | 5383 | return Qnil; |
diff --git a/src/filelock.c b/src/filelock.c index 20916ace50d..9f1968f07de 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -657,6 +657,8 @@ lock_file (Lisp_Object fn) | |||
| 657 | if (will_dump_p ()) | 657 | if (will_dump_p ()) |
| 658 | return; | 658 | return; |
| 659 | 659 | ||
| 660 | /* If the file name has special constructs in it, | ||
| 661 | call the corresponding file name handler. */ | ||
| 660 | Lisp_Object handler; | 662 | Lisp_Object handler; |
| 661 | handler = Ffind_file_name_handler (fn, Qlock_file); | 663 | handler = Ffind_file_name_handler (fn, Qlock_file); |
| 662 | if (!NILP (handler)) | 664 | if (!NILP (handler)) |
| @@ -705,20 +707,10 @@ lock_file (Lisp_Object fn) | |||
| 705 | } | 707 | } |
| 706 | 708 | ||
| 707 | static Lisp_Object | 709 | static Lisp_Object |
| 708 | unlock_file_body (Lisp_Object fn) | 710 | unlock_file (Lisp_Object fn) |
| 709 | { | 711 | { |
| 710 | char *lfname; | 712 | char *lfname; |
| 711 | 713 | ||
| 712 | /* If the file name has special constructs in it, | ||
| 713 | call the corresponding file name handler. */ | ||
| 714 | Lisp_Object handler; | ||
| 715 | handler = Ffind_file_name_handler (fn, Qunlock_file); | ||
| 716 | if (!NILP (handler)) | ||
| 717 | { | ||
| 718 | call2 (handler, Qunlock_file, fn); | ||
| 719 | return Qnil; | ||
| 720 | } | ||
| 721 | |||
| 722 | Lisp_Object lock_filename = make_lock_file_name (fn); | 714 | Lisp_Object lock_filename = make_lock_file_name (fn); |
| 723 | if (NILP (lock_filename)) | 715 | if (NILP (lock_filename)) |
| 724 | return Qnil; | 716 | return Qnil; |
| @@ -740,26 +732,12 @@ unlock_file_handle_error (Lisp_Object err) | |||
| 740 | return Qnil; | 732 | return Qnil; |
| 741 | } | 733 | } |
| 742 | 734 | ||
| 743 | void | ||
| 744 | unlock_file (Lisp_Object fn) | ||
| 745 | { | ||
| 746 | internal_condition_case_1 (unlock_file_body, | ||
| 747 | fn, | ||
| 748 | list1(Qfile_error), | ||
| 749 | unlock_file_handle_error); | ||
| 750 | } | ||
| 751 | |||
| 752 | #else /* MSDOS */ | 735 | #else /* MSDOS */ |
| 753 | void | 736 | void |
| 754 | lock_file (Lisp_Object fn) | 737 | lock_file (Lisp_Object fn) |
| 755 | { | 738 | { |
| 756 | } | 739 | } |
| 757 | 740 | ||
| 758 | void | ||
| 759 | unlock_file (Lisp_Object fn) | ||
| 760 | { | ||
| 761 | } | ||
| 762 | |||
| 763 | #endif /* MSDOS */ | 741 | #endif /* MSDOS */ |
| 764 | 742 | ||
| 765 | void | 743 | void |
| @@ -773,12 +751,11 @@ unlock_all_files (void) | |||
| 773 | b = XBUFFER (buf); | 751 | b = XBUFFER (buf); |
| 774 | if (STRINGP (BVAR (b, file_truename)) | 752 | if (STRINGP (BVAR (b, file_truename)) |
| 775 | && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) | 753 | && BUF_SAVE_MODIFF (b) < BUF_MODIFF (b)) |
| 776 | unlock_file (BVAR (b, file_truename)); | 754 | Funlock_file (BVAR (b, file_truename)); |
| 777 | } | 755 | } |
| 778 | } | 756 | } |
| 779 | 757 | ||
| 780 | DEFUN ("lock-file", Flock_file, Slock_file, | 758 | DEFUN ("lock-file", Flock_file, Slock_file, 1, 1, 0, |
| 781 | 0, 1, 0, | ||
| 782 | doc: /* Lock FILE. | 759 | doc: /* Lock FILE. |
| 783 | If the option `create-lockfiles' is nil, this does nothing. */) | 760 | If the option `create-lockfiles' is nil, this does nothing. */) |
| 784 | (Lisp_Object file) | 761 | (Lisp_Object file) |
| @@ -788,13 +765,28 @@ If the option `create-lockfiles' is nil, this does nothing. */) | |||
| 788 | return Qnil; | 765 | return Qnil; |
| 789 | } | 766 | } |
| 790 | 767 | ||
| 791 | DEFUN ("unlock-file", Funlock_file, Sunlock_file, | 768 | DEFUN ("unlock-file", Funlock_file, Sunlock_file, 1, 1, 0, |
| 792 | 0, 1, 0, | ||
| 793 | doc: /* Unlock FILE. */) | 769 | doc: /* Unlock FILE. */) |
| 794 | (Lisp_Object file) | 770 | (Lisp_Object file) |
| 795 | { | 771 | { |
| 772 | #ifndef MSDOS | ||
| 796 | CHECK_STRING (file); | 773 | CHECK_STRING (file); |
| 797 | unlock_file (file); | 774 | |
| 775 | /* If the file name has special constructs in it, | ||
| 776 | call the corresponding file name handler. */ | ||
| 777 | Lisp_Object handler; | ||
| 778 | handler = Ffind_file_name_handler (file, Qunlock_file); | ||
| 779 | if (!NILP (handler)) | ||
| 780 | { | ||
| 781 | call2 (handler, Qunlock_file, file); | ||
| 782 | return Qnil; | ||
| 783 | } | ||
| 784 | |||
| 785 | internal_condition_case_1 (unlock_file, | ||
| 786 | file, | ||
| 787 | list1 (Qfile_error), | ||
| 788 | unlock_file_handle_error); | ||
| 789 | #endif /* MSDOS */ | ||
| 798 | return Qnil; | 790 | return Qnil; |
| 799 | } | 791 | } |
| 800 | 792 | ||
| @@ -829,7 +821,7 @@ error did not occur. */) | |||
| 829 | { | 821 | { |
| 830 | if (SAVE_MODIFF < MODIFF | 822 | if (SAVE_MODIFF < MODIFF |
| 831 | && STRINGP (BVAR (current_buffer, file_truename))) | 823 | && STRINGP (BVAR (current_buffer, file_truename))) |
| 832 | unlock_file (BVAR (current_buffer, file_truename)); | 824 | Funlock_file (BVAR (current_buffer, file_truename)); |
| 833 | return Qnil; | 825 | return Qnil; |
| 834 | } | 826 | } |
| 835 | 827 | ||
| @@ -840,7 +832,7 @@ unlock_buffer (struct buffer *buffer) | |||
| 840 | { | 832 | { |
| 841 | if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer) | 833 | if (BUF_SAVE_MODIFF (buffer) < BUF_MODIFF (buffer) |
| 842 | && STRINGP (BVAR (buffer, file_truename))) | 834 | && STRINGP (BVAR (buffer, file_truename))) |
| 843 | unlock_file (BVAR (buffer, file_truename)); | 835 | Funlock_file (BVAR (buffer, file_truename)); |
| 844 | } | 836 | } |
| 845 | 837 | ||
| 846 | DEFUN ("file-locked-p", Ffile_locked_p, Sfile_locked_p, 1, 1, 0, | 838 | DEFUN ("file-locked-p", Ffile_locked_p, Sfile_locked_p, 1, 1, 0, |
diff --git a/src/lisp.h b/src/lisp.h index 4fb89236788..ce4b80a27ec 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4622,7 +4622,6 @@ extern void syms_of_sysdep (void); | |||
| 4622 | 4622 | ||
| 4623 | /* Defined in filelock.c. */ | 4623 | /* Defined in filelock.c. */ |
| 4624 | extern void lock_file (Lisp_Object); | 4624 | extern void lock_file (Lisp_Object); |
| 4625 | extern void unlock_file (Lisp_Object); | ||
| 4626 | extern void unlock_all_files (void); | 4625 | extern void unlock_all_files (void); |
| 4627 | extern void unlock_buffer (struct buffer *); | 4626 | extern void unlock_buffer (struct buffer *); |
| 4628 | extern void syms_of_filelock (void); | 4627 | extern void syms_of_filelock (void); |