(fa (tramp-get-file-property v localname "file-attributes"))
((not (stringp (car fa)))))))
;; Symlink to a non-existing target counts as nil.
+ ;; Protect against cyclic symbolic links.
((file-symlink-p ,filename)
- (file-exists-p (file-truename ,filename)))
+ (ignore-errors
+ (file-exists-p (file-truename ,filename))))
(t ,@body)))))))
(defmacro tramp-skeleton-file-local-copy (filename &rest body)
(defun tramp-handle-file-directory-p (filename)
"Like `file-directory-p' for Tramp files."
;; `file-truename' could raise an error, for example due to a cyclic
- ;; symlink. We don't protect this despite it, because other errors
- ;; might be worth to be visible, for example impossibility to mount
- ;; in tramp-gvfs.el.
- (eq (file-attribute-type (file-attributes (file-truename filename))) t))
+ ;; symlink.
+ (ignore-errors
+ (eq (file-attribute-type (file-attributes (file-truename filename))) t)))
(defun tramp-handle-file-equal-p (filename1 filename2)
"Like `file-equalp-p' for Tramp files."
(should (stringp (file-attribute-user-id attr)))
(should (stringp (file-attribute-group-id attr)))
+ ;; Symbolic links.
(tramp--test-ignore-make-symbolic-link-error
(should-error
(access-file tmp-name2 "error")
(file-remote-p (file-truename tmp-name1) 'localname)))
(delete-file tmp-name2)
- ;; A non-existent link target makes the file unaccessible.
- (make-symbolic-link "error" tmp-name2)
- (should (file-symlink-p tmp-name2))
- (should-error
- (access-file tmp-name2 "error")
- :type 'file-missing)
- ;; `file-ownership-preserved-p' should return t for
- ;; symlinked files to a non-existing target.
- (when test-file-ownership-preserved-p
- (should (file-ownership-preserved-p tmp-name2 'group)))
- (delete-file tmp-name2))
+ ;; A non-existent or cyclic link target makes the file
+ ;; unaccessible.
+ (dolist (target
+ `("does-not-exist" ,(file-name-nondirectory tmp-name2)))
+ (make-symbolic-link target tmp-name2)
+ (should (file-symlink-p tmp-name2))
+ (should-not (file-exists-p tmp-name2))
+ (should-not (file-directory-p tmp-name2))
+ (should-error
+ (access-file tmp-name2 "error")
+ :type
+ (if (string-equal target "does-not-exist")
+ 'file-missing 'file-error))
+ ;; `file-ownership-preserved-p' should return t for
+ ;; symlinked files to a non-existing or cyclic target.
+ (when test-file-ownership-preserved-p
+ (should (file-ownership-preserved-p tmp-name2 'group)))
+ (delete-file tmp-name2)))
;; Check, that "//" in symlinks are handled properly.
(with-temp-buffer
(make-symbolic-link tmp-name1 tmp-name2)
(should (file-symlink-p tmp-name1))
(should (file-symlink-p tmp-name2))
- (should-error
- (file-regular-p tmp-name1)
- :type 'file-error)
- (should-error
- (file-regular-p tmp-name2)
- :type 'file-error))))
+ (should-not (file-regular-p tmp-name1))
+ (should-not (file-regular-p tmp-name2)))))
;; Cleanup.
(ignore-errors