63
63
(declare-function tramp-smb-get-localname "tramp-smb")
64
64
(defvar ange-ftp-make-backup-files)
65
65
(defvar auto-save-file-name-transforms)
66
+ (defvar lock-file-name-transforms)
67
+ (defvar remote-file-name-inhibit-locks)
66
68
(defvar tramp-connection-properties)
67
69
(defvar tramp-copy-size-limit)
68
70
(defvar tramp-display-escape-sequence-regexp)
122
124
(setq auth-source-save-behavior nil
123
125
password-cache-expiry nil
124
126
remote-file-name-inhibit-cache nil
127
+ tramp-allow-unsafe-temporary-files t
125
128
tramp-cache-read-persistent-data t ;; For auth-sources.
126
129
tramp-copy-size-limit nil
127
130
tramp-persistency-file-name nil
@@ -5481,7 +5484,8 @@ Use direct async.")
5481
5484
5482
5485
(dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
5483
5486
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
5484
- (tmp-name2 (tramp--test-make-temp-name nil quoted)))
5487
+ (tmp-name2 (tramp--test-make-temp-name nil quoted))
5488
+ tramp-allow-unsafe-temporary-files)
5485
5489
5486
5490
(unwind-protect
5487
5491
(progn
@@ -5569,8 +5573,7 @@ Use direct async.")
5569
5573
5570
5574
;; Create temporary file. This shall check for sensible
5571
5575
;; files, owned by root.
5572
- (let ((tramp-auto-save-directory temporary-file-directory)
5573
- tramp-allow-unsafe-temporary-files)
5576
+ (let ((tramp-auto-save-directory temporary-file-directory))
5574
5577
(write-region "foo" nil tmp-name1)
5575
5578
(when (zerop (or (tramp-compat-file-attribute-user-id
5576
5579
(file-attributes tmp-name1))
@@ -5606,6 +5609,7 @@ Use direct async.")
5606
5609
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
5607
5610
(tmp-name2 (tramp--test-make-temp-name nil quoted))
5608
5611
(ange-ftp-make-backup-files t)
5612
+ tramp-allow-unsafe-temporary-files
5609
5613
;; These settings are not used by Tramp, so we ignore them.
5610
5614
version-control delete-old-versions
5611
5615
(kept-old-versions (default-toplevel-value 'kept-old-versions))
@@ -5716,7 +5720,6 @@ Use direct async.")
5716
5720
;; Create temporary file. This shall check for sensible
5717
5721
;; files, owned by root.
5718
5722
(let ((backup-directory-alist `(("." . ,temporary-file-directory)))
5719
- tramp-allow-unsafe-temporary-files
5720
5723
tramp-backup-directory-alist)
5721
5724
(write-region "foo" nil tmp-name1)
5722
5725
(when (zerop (or (tramp-compat-file-attribute-user-id
@@ -5749,13 +5752,18 @@ Use direct async.")
5749
5752
(skip-unless (not (tramp--test-ange-ftp-p)))
5750
5753
;; Since Emacs 28.1.
5751
5754
(skip-unless (and (fboundp 'lock-file) (fboundp 'unlock-file)))
5755
+ (skip-unless (and (fboundp 'file-locked-p) (fboundp 'make-lock-file-name)))
5752
5756
5757
+ ;; `lock-file', `unlock-file', `file-locked-p' and
5758
+ ;; `make-lock-file-name' exists since Emacs 28.1. We don't want to
5759
+ ;; see compiler warnings for older Emacsen.
5753
5760
(dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
5754
5761
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
5755
5762
(tmp-name2 (tramp--test-make-temp-name nil quoted))
5756
5763
(remote-file-name-inhibit-cache t)
5757
5764
(remote-file-name-inhibit-locks nil)
5758
5765
(create-lockfiles t)
5766
+ tramp-allow-unsafe-temporary-files
5759
5767
(inhibit-message t)
5760
5768
;; tramp-rclone.el and tramp-sshfs.el cache the mounted files.
5761
5769
(tramp-cleanup-connection-hook
@@ -5767,73 +5775,102 @@ Use direct async.")
5767
5775
(unwind-protect
5768
5776
(progn
5769
5777
;; A simple file lock.
5770
- (should-not (file-locked-p tmp-name1))
5771
- (lock-file tmp-name1)
5772
- (should (eq (file-locked-p tmp-name1) t))
5778
+ (should-not (with-no-warnings ( file-locked-p tmp-name1) ))
5779
+ (with-no-warnings ( lock-file tmp-name1) )
5780
+ (should (eq (with-no-warnings ( file-locked-p tmp-name1) ) t))
5773
5781
5774
5782
;; If it is locked already, nothing changes.
5775
- (lock-file tmp-name1)
5776
- (should (eq (file-locked-p tmp-name1) t))
5783
+ (with-no-warnings ( lock-file tmp-name1) )
5784
+ (should (eq (with-no-warnings ( file-locked-p tmp-name1) ) t))
5777
5785
5778
5786
;; A new connection changes process id, and also the
5779
5787
;; lockname contents.
5780
5788
(tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5781
- (should (stringp (file-locked-p tmp-name1)))
5789
+ (should (stringp (with-no-warnings ( file-locked-p tmp-name1) )))
5782
5790
5783
5791
;; When `remote-file-name-inhibit-locks' is set, nothing happens.
5784
5792
(tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5785
5793
(let ((remote-file-name-inhibit-locks t))
5786
- (lock-file tmp-name1)
5787
- (should-not (file-locked-p tmp-name1)))
5794
+ (with-no-warnings ( lock-file tmp-name1) )
5795
+ (should-not (with-no-warnings ( file-locked-p tmp-name1) )))
5788
5796
5789
5797
;; When `lock-file-name-transforms' is set, another lock
5790
5798
;; file is used.
5791
5799
(tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5792
5800
(let ((lock-file-name-transforms `((".*" ,tmp-name2))))
5793
5801
(should
5794
5802
(string-equal
5795
- (make-lock-file-name tmp-name1)
5796
- (make-lock-file-name tmp-name2)))
5797
- (lock-file tmp-name1)
5798
- (should (eq (file-locked-p tmp-name1) t))
5799
- (unlock-file tmp-name1)
5800
- (should-not (file-locked-p tmp-name1)))
5803
+ (with-no-warnings ( make-lock-file-name tmp-name1) )
5804
+ (with-no-warnings ( make-lock-file-name tmp-name2) )))
5805
+ (with-no-warnings ( lock-file tmp-name1) )
5806
+ (should (eq (with-no-warnings ( file-locked-p tmp-name1) ) t))
5807
+ (with-no-warnings ( unlock-file tmp-name1) )
5808
+ (should-not (with-no-warnings ( file-locked-p tmp-name1) )))
5801
5809
5802
5810
;; Steal the file lock.
5803
5811
(tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5804
5812
(cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?s)))
5805
- (lock-file tmp-name1))
5806
- (should (eq (file-locked-p tmp-name1) t))
5813
+ (with-no-warnings ( lock-file tmp-name1) ))
5814
+ (should (eq (with-no-warnings ( file-locked-p tmp-name1) ) t))
5807
5815
5808
5816
;; Ignore the file lock.
5809
5817
(tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5810
5818
(cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?p)))
5811
- (lock-file tmp-name1))
5812
- (should (stringp (file-locked-p tmp-name1)))
5819
+ (with-no-warnings ( lock-file tmp-name1) ))
5820
+ (should (stringp (with-no-warnings ( file-locked-p tmp-name1) )))
5813
5821
5814
5822
;; Quit the file lock machinery.
5815
5823
(tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5816
5824
(cl-letf (((symbol-function #'read-char) (lambda (&rest _args) ?q)))
5817
- (should-error (lock-file tmp-name1) :type 'file-locked)
5825
+ (with-no-warnings
5826
+ (should-error
5827
+ (lock-file tmp-name1)
5828
+ :type 'file-locked))
5818
5829
;; The same for `write-region'.
5819
5830
(should-error
5820
- (write-region "foo" nil tmp-name1) :type 'file-locked)
5831
+ (write-region "foo" nil tmp-name1)
5832
+ :type 'file-locked)
5821
5833
(should-error
5822
5834
(write-region "foo" nil tmp-name1 nil nil tmp-name1)
5823
5835
:type 'file-locked)
5824
5836
;; The same for `set-visited-file-name'.
5825
5837
(with-temp-buffer
5826
5838
(should-error
5827
- (set-visited-file-name tmp-name1) :type 'file-locked)))
5828
- (should (stringp (file-locked-p tmp-name1)))
5839
+ (set-visited-file-name tmp-name1)
5840
+ :type 'file-locked)))
5841
+ (should (stringp (with-no-warnings (file-locked-p tmp-name1))))
5829
5842
(should-not (file-exists-p tmp-name1)))
5830
5843
5831
5844
;; Cleanup.
5832
5845
(ignore-errors (delete-file tmp-name1))
5833
- (unlock-file tmp-name1)
5834
- (unlock-file tmp-name2)
5835
- (should-not (file-locked-p tmp-name1))
5836
- (should-not (file-locked-p tmp-name2))))))
5846
+ (with-no-warnings (unlock-file tmp-name1))
5847
+ (with-no-warnings (unlock-file tmp-name2))
5848
+ (should-not (with-no-warnings (file-locked-p tmp-name1)))
5849
+ (should-not (with-no-warnings (file-locked-p tmp-name2))))
5850
+
5851
+ (unwind-protect
5852
+ ;; Create temporary file. This shall check for sensible
5853
+ ;; files, owned by root.
5854
+ (let ((lock-file-name-transforms auto-save-file-name-transforms))
5855
+ (write-region "foo" nil tmp-name1)
5856
+ (when (zerop (or (tramp-compat-file-attribute-user-id
5857
+ (file-attributes tmp-name1))
5858
+ tramp-unknown-id-integer))
5859
+ (tramp-cleanup-connection
5860
+ tramp-test-vec 'keep-debug 'keep-password)
5861
+ (cl-letf (((symbol-function #'yes-or-no-p) #'ignore))
5862
+ (should-error
5863
+ (write-region "foo" nil tmp-name1)
5864
+ :type 'file-error))
5865
+ (tramp-cleanup-connection
5866
+ tramp-test-vec 'keep-debug 'keep-password)
5867
+ (cl-letf (((symbol-function #'yes-or-no-p)
5868
+ #'tramp--test-always))
5869
+ (write-region "foo" nil tmp-name1))))
5870
+
5871
+ ;; Cleanup.
5872
+ (ignore-errors (delete-file tmp-name1))
5873
+ (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)))))
5837
5874
5838
5875
;; The functions were introduced in Emacs 26.1.
5839
5876
(ert-deftest tramp-test40-make-nearby-temp-file ()
0 commit comments