From 01df347947c8785c7c21d5a2baa12de2ffde80dd Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Mon, 27 Dec 2021 19:51:58 +0100 Subject: [PATCH] Use `permission-denied' in Tramp tests, and more * lisp/net/tramp-crypt.el (tramp-crypt-maybe-open-connection): Simplify code. * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-system-info): Adapt for "mtp" method. * test/lisp/net/tramp-tests.el (tramp-test18-file-attributes): Use `permission-denied' error. Simplify code. (tramp-test24-file-acl, tramp-test26-file-name-completion): Simplify code. --- lisp/net/tramp-crypt.el | 2 +- lisp/net/tramp-gvfs.el | 6 ++++-- test/lisp/net/tramp-tests.el | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el index 4ff8e6bbf12..dd2ba23f0f0 100644 --- a/lisp/net/tramp-crypt.el +++ b/lisp/net/tramp-crypt.el @@ -323,7 +323,7 @@ connection if a previous connection has died for some reason." tramp-crypt-encfs-config (tramp-crypt-get-remote-dir vec))) (local-config (tramp-crypt-config-file-name vec))) ;; There is no local encfs6 config file. - (when (not (file-exists-p local-config)) + (unless (file-exists-p local-config) (if (and tramp-crypt-save-encfs-config-remote (file-exists-p remote-config)) ;; Copy remote encfs6 config file if possible. diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 6b0299aa097..292da5a1669 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -1524,8 +1524,10 @@ If FILE-SYSTEM is non-nil, return file system attributes." (when (or size free) (list (and size (string-to-number size)) (and free (string-to-number free)) - (and size used - (- (string-to-number size) (string-to-number used)))))))) + ;; "mtp" connections do not return "filesystem::used". + (or (and size used + (- (string-to-number size) (string-to-number used))) + (and free (string-to-number free)))))))) (defun tramp-gvfs-handle-make-directory (dir &optional parents) "Like `make-directory' for Tramp files." diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index f14d63af4cd..7ba5a870766 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -3405,12 +3405,12 @@ This tests also `access-file', `file-readable-p', (when (tramp--test-supports-set-file-modes-p) (write-region "foo" nil tmp-name1) ;; A file is always accessible for user "root". - (when (not (zerop (file-attribute-user-id - (file-attributes tmp-name1)))) + (unless + (zerop (file-attribute-user-id (file-attributes tmp-name1))) (set-file-modes tmp-name1 0) (should-error (access-file tmp-name1 "error") - :type 'file-error) + :type tramp-permission-denied) (set-file-modes tmp-name1 #o777)) (delete-file tmp-name1)) (should-error @@ -4095,7 +4095,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (should (file-acl tmp-name2)) (should (string-equal (file-acl tmp-name1) (file-acl tmp-name2))) ;; Different permissions mean different ACLs. - (when (not (tramp--test-windows-nt-or-smb-p)) + (unless (tramp--test-windows-nt-or-smb-p) (set-file-modes tmp-name1 #o777) (set-file-modes tmp-name2 #o444) (should-not @@ -4297,7 +4297,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." ;; Method and host name in completion mode. This kind of completion ;; does not work on MS Windows. - (when (not (memq system-type '(cygwin windows-nt))) + (unless (memq system-type '(cygwin windows-nt)) (let ((method (file-remote-p tramp-test-temporary-file-directory 'method)) (host (file-remote-p tramp-test-temporary-file-directory 'host)) (orig-syntax tramp-syntax)) -- 2.39.2