aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2022-02-03 14:21:23 +0100
committerMichael Albinus2022-02-03 14:21:23 +0100
commit895562a8b24fc637fb422d38ea64e7d445b3480d (patch)
treedde4c209104e3c100be362433278bd2bde74523d /test
parent3bd8a8bb91d5bf56216541f359c69c789c942b16 (diff)
downloademacs-895562a8b24fc637fb422d38ea64e7d445b3480d.tar.gz
emacs-895562a8b24fc637fb422d38ea64e7d445b3480d.zip
Implement file modification check in Tramp
* lisp/net/tramp.el (tramp-handle-lock-file): Check, whether FILE is modified. * test/lisp/net/tramp-tests.el (tramp-test39-detect-external-change): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/tramp-tests.el72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 01fe7355f45..b41824a6cf3 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -6018,6 +6018,78 @@ Use direct async.")
6018 (ignore-errors (delete-file tmp-name1)) 6018 (ignore-errors (delete-file tmp-name1))
6019 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password))))) 6019 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)))))
6020 6020
6021;; The function was introduced in Emacs 28.1.
6022(ert-deftest tramp-test39-detect-external-change ()
6023 "Check that an external file modification is reported."
6024 (skip-unless (tramp--test-enabled))
6025 (skip-unless (not (tramp--test-ange-ftp-p)))
6026 ;; Since Emacs 28.1.
6027 (skip-unless (fboundp 'file-locked-p))
6028
6029 (dolist (quoted (if (tramp--test-expensive-test-p) '(nil t) '(nil)))
6030 (dolist (create-lockfiles '(nil t))
6031 (let ((tmp-name (tramp--test-make-temp-name nil quoted))
6032 (remote-file-name-inhibit-cache t)
6033 (remote-file-name-inhibit-locks nil)
6034 tramp-allow-unsafe-temporary-files
6035 (inhibit-message t)
6036 ;; tramp-rclone.el and tramp-sshfs.el cache the mounted files.
6037 (tramp-fuse-unmount-on-cleanup t)
6038 auto-save-default
6039 (backup-inhibited t)
6040 noninteractive)
6041 (with-temp-buffer
6042 (unwind-protect
6043 (progn
6044 (setq buffer-file-name tmp-name
6045 buffer-file-truename tmp-name)
6046 (insert "foo")
6047 ;; Bug#53207: with `create-lockfiles' nil, saving the
6048 ;; buffer results in a prompt.
6049 (cl-letf (((symbol-function 'yes-or-no-p)
6050 (lambda (_) (ert-fail "Test failed unexpectedly"))))
6051 (save-buffer))
6052 (should-not (file-locked-p tmp-name))
6053
6054 ;; For local files, just changing the file
6055 ;; modification on disk doesn't hurt, because file
6056 ;; contents in buffer and on disk are equal. For
6057 ;; remote files, file contents is not compared. We
6058 ;; mock an older modification time in buffer, because
6059 ;; Tramp regards modification times equal if they
6060 ;; differ for less than 2 seconds.
6061 (set-visited-file-modtime (time-add (current-time) -60))
6062 ;; Some Tramp methods cannot check the file
6063 ;; modification time properly, for them it doesn't
6064 ;; make sense to test.
6065 (when (not (verify-visited-file-modtime))
6066 (cl-letf (((symbol-function 'read-char-choice)
6067 (lambda (prompt &rest _) (message "%s" prompt) ?y)))
6068 (ert-with-message-capture captured-messages
6069 (insert "bar")
6070 (when create-lockfiles
6071 (should (string-match-p
6072 (format
6073 "^%s changed on disk; really edit the buffer\\?"
6074 (if (tramp--test-crypt-p)
6075 ".+" (file-name-nondirectory tmp-name)))
6076 captured-messages))
6077 (should (file-locked-p tmp-name)))))
6078
6079 ;; `save-buffer' removes the file lock.
6080 (cl-letf (((symbol-function 'yes-or-no-p) #'tramp--test-always)
6081 ((symbol-function 'read-char-choice)
6082 (lambda (&rest _) ?y)))
6083 (save-buffer))
6084 (should-not (file-locked-p tmp-name))))
6085
6086 ;; Cleanup.
6087 (set-buffer-modified-p nil)
6088 (ignore-errors (delete-file tmp-name))
6089 (tramp-cleanup-connection
6090 tramp-test-vec 'keep-debug 'keep-password)))))))
6091
6092;; The functions were introduced in Emacs 26.1.
6021(ert-deftest tramp-test40-make-nearby-temp-file () 6093(ert-deftest tramp-test40-make-nearby-temp-file ()
6022 "Check `make-nearby-temp-file' and `temporary-file-directory'." 6094 "Check `make-nearby-temp-file' and `temporary-file-directory'."
6023 (skip-unless (tramp--test-enabled)) 6095 (skip-unless (tramp--test-enabled))