diff options
| author | Michael Albinus | 2021-07-09 18:14:19 +0200 |
|---|---|---|
| committer | Michael Albinus | 2021-07-09 18:14:19 +0200 |
| commit | 9ce6541ac9710933beca7f9944087fe4849d5ae9 (patch) | |
| tree | 133344956b38933f504071bfa114fc712296f43c /src | |
| parent | 2870a72d0d6675e189457394ac421bd8e5ab4561 (diff) | |
| download | emacs-9ce6541ac9710933beca7f9944087fe4849d5ae9.tar.gz emacs-9ce6541ac9710933beca7f9944087fe4849d5ae9.zip | |
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')
| -rw-r--r-- | src/buffer.c | 2 | ||||
| -rw-r--r-- | src/fileio.c | 2 | ||||
| -rw-r--r-- | src/filelock.c | 74 | ||||
| -rw-r--r-- | src/insdel.c | 2 | ||||
| -rw-r--r-- | src/lisp.h | 1 |
5 files changed, 37 insertions, 44 deletions
diff --git a/src/buffer.c b/src/buffer.c index 3cd47fede36..bbb0edd792c 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1449,7 +1449,7 @@ state of the current buffer. Use with care. */) | |||
| 1449 | { | 1449 | { |
| 1450 | bool already = SAVE_MODIFF < MODIFF; | 1450 | bool already = SAVE_MODIFF < MODIFF; |
| 1451 | if (!already && !NILP (flag)) | 1451 | if (!already && !NILP (flag)) |
| 1452 | lock_file (fn); | 1452 | Flock_file (fn); |
| 1453 | else if (already && NILP (flag)) | 1453 | else if (already && NILP (flag)) |
| 1454 | Funlock_file (fn); | 1454 | Funlock_file (fn); |
| 1455 | } | 1455 | } |
diff --git a/src/fileio.c b/src/fileio.c index 30e6caf7ea5..04c9d7d4af3 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -5168,7 +5168,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename, | |||
| 5168 | 5168 | ||
| 5169 | if (open_and_close_file && !auto_saving) | 5169 | if (open_and_close_file && !auto_saving) |
| 5170 | { | 5170 | { |
| 5171 | lock_file (lockname); | 5171 | Flock_file (lockname); |
| 5172 | file_locked = 1; | 5172 | file_locked = 1; |
| 5173 | } | 5173 | } |
| 5174 | 5174 | ||
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) | |||
| 622 | static Lisp_Object | 622 | static Lisp_Object |
| 623 | make_lock_file_name (Lisp_Object fn) | 623 | make_lock_file_name (Lisp_Object fn) |
| 624 | { | 624 | { |
| 625 | Lisp_Object func = intern ("make-lock-file-name"); | 625 | return call1 (Qmake_lock_file_name, Fexpand_file_name (fn, Qnil)); |
| 626 | if (NILP (Fboundp (func))) | ||
| 627 | return Qnil; | ||
| 628 | return call1 (func, Fexpand_file_name (fn, Qnil)); | ||
| 629 | } | 626 | } |
| 630 | 627 | ||
| 631 | /* lock_file locks file FN, | 628 | /* lock_file locks file FN, |
| @@ -646,7 +643,7 @@ make_lock_file_name (Lisp_Object fn) | |||
| 646 | This function can signal an error, or return t meaning | 643 | This function can signal an error, or return t meaning |
| 647 | take away the lock, or return nil meaning ignore the lock. */ | 644 | take away the lock, or return nil meaning ignore the lock. */ |
| 648 | 645 | ||
| 649 | void | 646 | static Lisp_Object |
| 650 | lock_file (Lisp_Object fn) | 647 | lock_file (Lisp_Object fn) |
| 651 | { | 648 | { |
| 652 | lock_info_type lock_info; | 649 | lock_info_type lock_info; |
| @@ -655,7 +652,7 @@ lock_file (Lisp_Object fn) | |||
| 655 | Uncompressing wtmp files uses call-process, which does not work | 652 | Uncompressing wtmp files uses call-process, which does not work |
| 656 | in an uninitialized Emacs. */ | 653 | in an uninitialized Emacs. */ |
| 657 | if (will_dump_p ()) | 654 | if (will_dump_p ()) |
| 658 | return; | 655 | return Qnil; |
| 659 | 656 | ||
| 660 | /* If the file name has special constructs in it, | 657 | /* If the file name has special constructs in it, |
| 661 | call the corresponding file name handler. */ | 658 | call the corresponding file name handler. */ |
| @@ -663,13 +660,12 @@ lock_file (Lisp_Object fn) | |||
| 663 | handler = Ffind_file_name_handler (fn, Qlock_file); | 660 | handler = Ffind_file_name_handler (fn, Qlock_file); |
| 664 | if (!NILP (handler)) | 661 | if (!NILP (handler)) |
| 665 | { | 662 | { |
| 666 | call2 (handler, Qlock_file, fn); | 663 | return call2 (handler, Qlock_file, fn); |
| 667 | return; | ||
| 668 | } | 664 | } |
| 669 | 665 | ||
| 670 | Lisp_Object lock_filename = make_lock_file_name (fn); | 666 | Lisp_Object lock_filename = make_lock_file_name (fn); |
| 671 | if (NILP (lock_filename)) | 667 | if (NILP (lock_filename)) |
| 672 | return; | 668 | return Qnil; |
| 673 | char *lfname = SSDATA (ENCODE_FILE (lock_filename)); | 669 | char *lfname = SSDATA (ENCODE_FILE (lock_filename)); |
| 674 | 670 | ||
| 675 | /* See if this file is visited and has changed on disk since it was | 671 | /* See if this file is visited and has changed on disk since it was |
| @@ -678,32 +674,29 @@ lock_file (Lisp_Object fn) | |||
| 678 | if (!NILP (subject_buf) | 674 | if (!NILP (subject_buf) |
| 679 | && NILP (Fverify_visited_file_modtime (subject_buf)) | 675 | && NILP (Fverify_visited_file_modtime (subject_buf)) |
| 680 | && !NILP (Ffile_exists_p (lock_filename)) | 676 | && !NILP (Ffile_exists_p (lock_filename)) |
| 681 | && !(create_lockfiles && current_lock_owner (NULL, lfname) == -2)) | 677 | && current_lock_owner (NULL, lfname) != -2) |
| 682 | call1 (intern ("userlock--ask-user-about-supersession-threat"), fn); | 678 | call1 (intern ("userlock--ask-user-about-supersession-threat"), fn); |
| 683 | 679 | ||
| 684 | /* Don't do locking if the user has opted out. */ | 680 | /* Try to lock the lock. FIXME: This ignores errors when |
| 685 | if (create_lockfiles) | 681 | lock_if_free returns a positive errno value. */ |
| 682 | if (lock_if_free (&lock_info, lfname) < 0) | ||
| 686 | { | 683 | { |
| 687 | /* Try to lock the lock. FIXME: This ignores errors when | 684 | /* Someone else has the lock. Consider breaking it. */ |
| 688 | lock_if_free returns a positive errno value. */ | 685 | Lisp_Object attack; |
| 689 | if (lock_if_free (&lock_info, lfname) < 0) | 686 | char *dot = lock_info.dot; |
| 690 | { | 687 | ptrdiff_t pidlen = lock_info.colon - (dot + 1); |
| 691 | /* Someone else has the lock. Consider breaking it. */ | 688 | static char const replacement[] = " (pid "; |
| 692 | Lisp_Object attack; | 689 | int replacementlen = sizeof replacement - 1; |
| 693 | char *dot = lock_info.dot; | 690 | memmove (dot + replacementlen, dot + 1, pidlen); |
| 694 | ptrdiff_t pidlen = lock_info.colon - (dot + 1); | 691 | strcpy (dot + replacementlen + pidlen, ")"); |
| 695 | static char const replacement[] = " (pid "; | 692 | memcpy (dot, replacement, replacementlen); |
| 696 | int replacementlen = sizeof replacement - 1; | 693 | attack = call2 (intern ("ask-user-about-lock"), fn, |
| 697 | memmove (dot + replacementlen, dot + 1, pidlen); | 694 | build_string (lock_info.user)); |
| 698 | strcpy (dot + replacementlen + pidlen, ")"); | 695 | /* Take the lock if the user said so. */ |
| 699 | memcpy (dot, replacement, replacementlen); | 696 | if (!NILP (attack)) |
| 700 | attack = call2 (intern ("ask-user-about-lock"), fn, | 697 | lock_file_1 (lfname, 1); |
| 701 | build_string (lock_info.user)); | ||
| 702 | /* Take the lock if the user said so. */ | ||
| 703 | if (!NILP (attack)) | ||
| 704 | lock_file_1 (lfname, 1); | ||
| 705 | } | ||
| 706 | } | 698 | } |
| 699 | return Qnil; | ||
| 707 | } | 700 | } |
| 708 | 701 | ||
| 709 | static Lisp_Object | 702 | static Lisp_Object |
| @@ -732,12 +725,6 @@ unlock_file_handle_error (Lisp_Object err) | |||
| 732 | return Qnil; | 725 | return Qnil; |
| 733 | } | 726 | } |
| 734 | 727 | ||
| 735 | #else /* MSDOS */ | ||
| 736 | void | ||
| 737 | lock_file (Lisp_Object fn) | ||
| 738 | { | ||
| 739 | } | ||
| 740 | |||
| 741 | #endif /* MSDOS */ | 728 | #endif /* MSDOS */ |
| 742 | 729 | ||
| 743 | void | 730 | void |
| @@ -760,8 +747,14 @@ DEFUN ("lock-file", Flock_file, Slock_file, 1, 1, 0, | |||
| 760 | If the option `create-lockfiles' is nil, this does nothing. */) | 747 | If the option `create-lockfiles' is nil, this does nothing. */) |
| 761 | (Lisp_Object file) | 748 | (Lisp_Object file) |
| 762 | { | 749 | { |
| 763 | CHECK_STRING (file); | 750 | #ifndef MSDOS |
| 764 | lock_file (file); | 751 | /* Don't do locking if the user has opted out. */ |
| 752 | if (create_lockfiles) | ||
| 753 | { | ||
| 754 | CHECK_STRING (file); | ||
| 755 | lock_file (file); | ||
| 756 | } | ||
| 757 | #endif /* MSDOS */ | ||
| 765 | return Qnil; | 758 | return Qnil; |
| 766 | } | 759 | } |
| 767 | 760 | ||
| @@ -805,7 +798,7 @@ If the option `create-lockfiles' is nil, this does nothing. */) | |||
| 805 | CHECK_STRING (file); | 798 | CHECK_STRING (file); |
| 806 | if (SAVE_MODIFF < MODIFF | 799 | if (SAVE_MODIFF < MODIFF |
| 807 | && !NILP (file)) | 800 | && !NILP (file)) |
| 808 | lock_file (file); | 801 | Flock_file (file); |
| 809 | return Qnil; | 802 | return Qnil; |
| 810 | } | 803 | } |
| 811 | 804 | ||
| @@ -892,6 +885,7 @@ Info node `(emacs)Interlocking'. */); | |||
| 892 | DEFSYM (Qlock_file, "lock-file"); | 885 | DEFSYM (Qlock_file, "lock-file"); |
| 893 | DEFSYM (Qunlock_file, "unlock-file"); | 886 | DEFSYM (Qunlock_file, "unlock-file"); |
| 894 | DEFSYM (Qfile_locked_p, "file-locked-p"); | 887 | DEFSYM (Qfile_locked_p, "file-locked-p"); |
| 888 | DEFSYM (Qmake_lock_file_name, "make-lock-file-name"); | ||
| 895 | 889 | ||
| 896 | defsubr (&Slock_file); | 890 | defsubr (&Slock_file); |
| 897 | defsubr (&Sunlock_file); | 891 | defsubr (&Sunlock_file); |
diff --git a/src/insdel.c b/src/insdel.c index e38b091f542..e66120eb08a 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -1989,7 +1989,7 @@ prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end, | |||
| 1989 | /* Make binding buffer-file-name to nil effective. */ | 1989 | /* Make binding buffer-file-name to nil effective. */ |
| 1990 | && !NILP (BVAR (base_buffer, filename)) | 1990 | && !NILP (BVAR (base_buffer, filename)) |
| 1991 | && SAVE_MODIFF >= MODIFF) | 1991 | && SAVE_MODIFF >= MODIFF) |
| 1992 | lock_file (BVAR (base_buffer, file_truename)); | 1992 | Flock_file (BVAR (base_buffer, file_truename)); |
| 1993 | 1993 | ||
| 1994 | /* If `select-active-regions' is non-nil, save the region text. */ | 1994 | /* If `select-active-regions' is non-nil, save the region text. */ |
| 1995 | /* FIXME: Move this to Elisp (via before-change-functions). */ | 1995 | /* FIXME: Move this to Elisp (via before-change-functions). */ |
diff --git a/src/lisp.h b/src/lisp.h index ce4b80a27ec..1795b9d811b 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -4621,7 +4621,6 @@ extern int str_collate (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object); | |||
| 4621 | extern void syms_of_sysdep (void); | 4621 | 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); | ||
| 4625 | extern void unlock_all_files (void); | 4624 | extern void unlock_all_files (void); |
| 4626 | extern void unlock_buffer (struct buffer *); | 4625 | extern void unlock_buffer (struct buffer *); |
| 4627 | extern void syms_of_filelock (void); | 4626 | extern void syms_of_filelock (void); |