"Like `file-regular-p' for Tramp files."
(and (file-exists-p filename)
;; Sometimes, `file-attributes' does not return a proper value
- ;; even if `file-exists-p' does.
- (when-let ((attr (file-attributes filename)))
- (eq ?- (aref (file-attribute-modes attr) 0)))))
+ ;; even if `file-exists-p' does. Protect by `ignore-errors',
+ ;; because `file-truename' could raise an error for cyclic
+ ;; symlinks.
+ (ignore-errors
+ (when-let ((attr (file-attributes filename)))
+ (cond
+ ((eq ?- (aref (file-attribute-modes attr) 0)))
+ ((eq ?l (aref (file-attribute-modes attr) 0))
+ (file-regular-p (file-truename filename))))))))
(defun tramp-handle-file-remote-p (filename &optional identification connected)
"Like `file-remote-p' for Tramp files."
(access-file tmp-name1 "error")
:type 'file-missing)
+ (should-not (file-exists-p tmp-name1))
+ (should-not (file-readable-p tmp-name1))
+ (should-not (file-regular-p tmp-name1))
;; `file-ownership-preserved-p' should return t for
;; non-existing files.
(when test-file-ownership-preserved-p
(should (file-exists-p tmp-name1))
(should (file-readable-p tmp-name1))
(should-not (file-regular-p tmp-name1))
- (should-not (access-file tmp-name1 ""))
+ (should-not (access-file tmp-name1 "error"))
(when test-file-ownership-preserved-p
(should (file-ownership-preserved-p tmp-name1 'group)))
(setq attr (file-attributes tmp-name1))
(tramp--test-ignore-make-symbolic-link-error
(write-region "foo" nil tmp-name1)
(should (file-exists-p tmp-name1))
+ (should (file-regular-p tmp-name1))
(make-symbolic-link tmp-name1 tmp-name2)
+ (should (file-exists-p tmp-name2))
+ (should (file-regular-p tmp-name2))
(should
(string-equal
(funcall
(string-equal tmp-name1 (file-symlink-p tmp-name3))))
;; Check directory as newname.
(make-directory tmp-name4)
+ (should (file-directory-p tmp-name4))
+ (should-not (file-regular-p tmp-name4))
(when (tramp--test-expensive-test-p)
(should-error
(make-symbolic-link tmp-name1 tmp-name4)
(file-symlink-p tmp-name5)))
;; Check, that files in symlinked directories still work.
(make-symbolic-link tmp-name4 tmp-name6)
+ (should (file-symlink-p tmp-name6))
+ (should-not (file-regular-p tmp-name6))
(write-region "foo" nil (expand-file-name "foo" tmp-name6))
(delete-file (expand-file-name "foo" tmp-name6))
(should-not (file-exists-p (expand-file-name "foo" tmp-name4)))
(tramp--test-ignore-make-symbolic-link-error
(write-region "foo" nil tmp-name1)
(should (file-exists-p tmp-name1))
+ (should (file-regular-p tmp-name1))
(should (string-equal tmp-name1 (file-truename tmp-name1)))
(make-symbolic-link tmp-name1 tmp-name2)
(should (file-symlink-p tmp-name2))
+ (should (file-regular-p tmp-name2))
(should-not (string-equal tmp-name2 (file-truename tmp-name2)))
(should
(string-equal (file-truename tmp-name1) (file-truename tmp-name2)))
(let ((default-directory ert-remote-temporary-file-directory))
(make-symbolic-link (file-name-nondirectory tmp-name1) tmp-name2))
(should (file-symlink-p tmp-name2))
+ (should (file-regular-p tmp-name2))
(should-not (string-equal tmp-name2 (file-truename tmp-name2)))
(should
(string-equal (file-truename tmp-name1) (file-truename tmp-name2)))
(if quoted #'tramp-compat-file-name-unquote #'identity) penguin)
tmp-name2)
(should (file-symlink-p tmp-name2))
+ (should-not (file-regular-p tmp-name2))
(should
(string-equal
(file-truename tmp-name2)
(unless (tramp--test-windows-nt-p)
(make-symbolic-link tmp-name1 tmp-name3)
(should (file-symlink-p tmp-name3))
+ (should-not (file-regular-p tmp-name3))
(should-not (string-equal tmp-name3 (file-truename tmp-name3)))
;; `file-truename' returns a quoted file name for `tmp-name3'.
;; We must unquote it.
(make-symbolic-link
tmp-name3
(setq tmp-name3 (tramp--test-make-temp-name nil quoted))))
+ (should-not (file-regular-p tmp-name2))
+ (should-not (file-regular-p tmp-name3))
(should
(string-equal
(file-truename tmp-name2)
(tramp--test-ignore-make-symbolic-link-error
(make-symbolic-link tmp-name2 tmp-name1)
(should (file-symlink-p tmp-name1))
+ (should-not (file-regular-p tmp-name1))
+ (should-not (file-regular-p tmp-name2))
(if (tramp--test-smb-p)
;; The symlink command of "smbclient" detects the
;; cycle already.
:type 'file-error)
(make-symbolic-link tmp-name1 tmp-name2)
(should (file-symlink-p tmp-name2))
+ (should-not (file-regular-p tmp-name2))
(should-error
(file-truename tmp-name1)
:type 'file-error))))