aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Albinus2021-07-07 18:36:53 +0200
committerMichael Albinus2021-07-07 18:36:53 +0200
commitd35868bec96718705c9bc8aaac3bc583c837033f (patch)
treea92e9b2fe0fddc4add787acb563aa798fccbe3b0 /src
parent90c89e8bdeca61aceae79e4c60a9a51800574914 (diff)
downloademacs-d35868bec96718705c9bc8aaac3bc583c837033f.tar.gz
emacs-d35868bec96718705c9bc8aaac3bc583c837033f.zip
Implement file locks for remote files (Bug#49261)
* doc/lispref/files.texi (Magic File Names): Add file-locked-p, lock-file and unlock-file. * etc/NEWS: Tramp supports file locks now. * lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-adb-handle-write-region): Handle LOCKNAME. * lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. * lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-crypt-handle-file-locked-p, tramp-crypt-handle-lock-file) (tramp-crypt-handle-unlock-file): New defun. * lisp/net/tramp-fuse.el (tramp-fuse-mounted-p): Simplify. (tramp-fuse-unmount): New defun. * lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-gvfs-maybe-open-connection): Set "lock-pid" connection property. * lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-rclone-maybe-open-connection): Set "lock-pid" connection property. * lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-sh-handle-write-region): Handle LOCKNAME. * lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-smb-handle-copy-directory): Use `sleep-for'. (tramp-smb-handle-write-region): Handle LOCKNAME. * lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-sshfs-handle-write-region): Handle LOCKNAME. (tramp-sshfs-maybe-open-connection): Set "lock-pid" connection property. * lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-sudoedit-maybe-open-connection): Set "lock-pid" connection property. * lisp/net/tramp.el (tramp-file-name-for-operation): Add `file-locked-p', `lock-file' and `unlock-file'. (tramp-make-lock-name, tramp-get-lock-file, tramp-get-lock-pid) (tramp-handle-file-locked-p, tramp-handle-lock-file) (tramp-handle-unlock-file): New defuns. (tramp-lock-file-contents-regexp): New regexp. (tramp-handle-write-region): Handle LOCKNAME. * src/filelock.c (lock_file, unlock_file_body, Ffile_locked_p): Call handler if exists. (Flock_file, Funlock_file): New defuns. (Qlock_file, Qunlock_file, Qfile_locked_p): Declare symbols. (Slock_file, Sunlock_file): Declare subroutines. * test/lisp/net/tramp-archive-tests.el (tramp-archive-test40-make-nearby-temp-file) (tramp-archive-test43-file-system-info): Rename. * test/lisp/net/tramp-tests.el (top): Set `create-lockfiles' to nil. (tramp--test-fuse-p): New defun. (tramp-test14-delete-directory): Use it. (tramp-test39-lock-file): New test. (tramp-test40-make-nearby-temp-file) (tramp-test41-special-characters) (tramp-test41-special-characters-with-stat) (tramp-test41-special-characters-with-perl) (tramp-test41-special-characters-with-ls, tramp-test42-utf8) (tramp-test42-utf8-with-stat, tramp-test42-utf8-with-perl) (tramp-test42-utf8-with-ls, tramp-test43-file-system-info) (tramp-test44-asynchronous-requests, tramp-test45-auto-load) (tramp-test45-delay-load, tramp-test45-recursive-load) (tramp-test45-remote-load-path, tramp-test46-unload): Rename. (tramp--test-special-characters, tramp--test-utf8) (tramp--test-asynchronous-requests-timeout): Modify docstring.
Diffstat (limited to 'src')
-rw-r--r--src/filelock.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 446a262a1ce..dcdc635c25e 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -671,6 +671,16 @@ lock_file (Lisp_Object fn)
671 if (will_dump_p ()) 671 if (will_dump_p ())
672 return; 672 return;
673 673
674 /* If the file name has special constructs in it,
675 call the corresponding file name handler. */
676 Lisp_Object handler;
677 handler = Ffind_file_name_handler (fn, Qlock_file);
678 if (!NILP (handler))
679 {
680 call2 (handler, Qlock_file, fn);
681 return;
682 }
683
674 orig_fn = fn; 684 orig_fn = fn;
675 fn = Fexpand_file_name (fn, Qnil); 685 fn = Fexpand_file_name (fn, Qnil);
676#ifdef WINDOWSNT 686#ifdef WINDOWSNT
@@ -725,6 +735,16 @@ unlock_file_body (Lisp_Object fn)
725 char *lfname; 735 char *lfname;
726 USE_SAFE_ALLOCA; 736 USE_SAFE_ALLOCA;
727 737
738 /* If the file name has special constructs in it,
739 call the corresponding file name handler. */
740 Lisp_Object handler;
741 handler = Ffind_file_name_handler (fn, Qunlock_file);
742 if (!NILP (handler))
743 {
744 call2 (handler, Qunlock_file, fn);
745 return Qnil;
746 }
747
728 Lisp_Object filename = Fexpand_file_name (fn, Qnil); 748 Lisp_Object filename = Fexpand_file_name (fn, Qnil);
729 fn = ENCODE_FILE (filename); 749 fn = ENCODE_FILE (filename);
730 750
@@ -784,6 +804,27 @@ unlock_all_files (void)
784 } 804 }
785} 805}
786 806
807DEFUN ("lock-file", Flock_file, Slock_file,
808 0, 1, 0,
809 doc: /* Lock FILE.
810If the option `create-lockfiles' is nil, this does nothing. */)
811 (Lisp_Object file)
812{
813 CHECK_STRING (file);
814 lock_file (file);
815 return Qnil;
816}
817
818DEFUN ("unlock-file", Funlock_file, Sunlock_file,
819 0, 1, 0,
820 doc: /* Unlock FILE. */)
821 (Lisp_Object file)
822{
823 CHECK_STRING (file);
824 unlock_file (file);
825 return Qnil;
826}
827
787DEFUN ("lock-buffer", Flock_buffer, Slock_buffer, 828DEFUN ("lock-buffer", Flock_buffer, Slock_buffer,
788 0, 1, 0, 829 0, 1, 0,
789 doc: /* Lock FILE, if current buffer is modified. 830 doc: /* Lock FILE, if current buffer is modified.
@@ -844,6 +885,15 @@ t if it is locked by you, else a string saying which user has locked it. */)
844 lock_info_type locker; 885 lock_info_type locker;
845 USE_SAFE_ALLOCA; 886 USE_SAFE_ALLOCA;
846 887
888 /* If the file name has special constructs in it,
889 call the corresponding file name handler. */
890 Lisp_Object handler;
891 handler = Ffind_file_name_handler (filename, Qfile_locked_p);
892 if (!NILP (handler))
893 {
894 return call2 (handler, Qfile_locked_p, filename);
895 }
896
847 filename = Fexpand_file_name (filename, Qnil); 897 filename = Fexpand_file_name (filename, Qnil);
848 Lisp_Object encoded_filename = ENCODE_FILE (filename); 898 Lisp_Object encoded_filename = ENCODE_FILE (filename);
849 MAKE_LOCK_NAME (lfname, encoded_filename); 899 MAKE_LOCK_NAME (lfname, encoded_filename);
@@ -876,7 +926,13 @@ The name of the (per-buffer) lockfile is constructed by prepending a
876Info node `(emacs)Interlocking'. */); 926Info node `(emacs)Interlocking'. */);
877 create_lockfiles = true; 927 create_lockfiles = true;
878 928
879 defsubr (&Sunlock_buffer); 929 DEFSYM (Qlock_file, "lock-file");
930 DEFSYM (Qunlock_file, "unlock-file");
931 DEFSYM (Qfile_locked_p, "file-locked-p");
932
933 defsubr (&Slock_file);
934 defsubr (&Sunlock_file);
880 defsubr (&Slock_buffer); 935 defsubr (&Slock_buffer);
936 defsubr (&Sunlock_buffer);
881 defsubr (&Sfile_locked_p); 937 defsubr (&Sfile_locked_p);
882} 938}