From: Michael Albinus Date: Wed, 11 May 2022 16:02:13 +0000 (+0200) Subject: Improve handling of `tramp-set-file-uid-gid' X-Git-Tag: emacs-29.0.90~1910^2~789 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4e7879f807b43416568154d31bc49d3e7393d583;p=emacs.git Improve handling of `tramp-set-file-uid-gid' * lisp/net/tramp.el (tramp-skeleton-write-region): Call `tramp-set-file-uid-gid' properly. (tramp-set-file-uid-gid): Handle also `tramp-crypt-file-name-handler'. * test/lisp/net/tramp-tests.el (tramp-test27-load): Adapt test. --- diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 74155d1722e..1851047ccf5 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -6133,4 +6133,5 @@ function cell is returned to be applied on a buffer." ;; * Support hostname canonicalization in ~/.ssh/config. ;; + ;;; tramp-sh.el ends here diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 9413f7954f4..b26346443da 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3435,7 +3435,7 @@ BODY is the backend specific code." ;; We must protect `last-coding-system-used', now we have ;; set it to its correct value. - (let (last-coding-system-used) + (let (last-coding-system-used (need-chown t)) ;; Set file modification time. (when (or (eq ,visit t) (stringp ,visit)) (when-let ((file-attr (file-attributes filename 'integer))) @@ -3445,10 +3445,13 @@ BODY is the backend specific code." ;; `file-precious-flag' is set. (or (file-attribute-modification-time file-attr) (current-time))) - ;; Set the ownership. (unless (and (= (file-attribute-user-id file-attr) uid) (= (file-attribute-group-id file-attr) gid)) - (tramp-set-file-uid-gid filename uid gid))))) + (setq need-chown nil)))) + + ;; Set the ownership. + (when need-chown + (tramp-set-file-uid-gid filename uid gid))) ;; Unlock file. (when file-locked @@ -5627,7 +5630,9 @@ If FILENAME is remote, a file name handler is called." (setq gid (file-attribute-group-id (file-attributes dir))))) (if (tramp-tramp-file-p filename) - (tramp-file-name-handler #'tramp-set-file-uid-gid filename uid gid) + (funcall (if (tramp-crypt-file-name-p filename) + #'tramp-crypt-file-name-handler #'tramp-file-name-handler) + #'tramp-set-file-uid-gid filename uid gid) ;; On W32 systems, "chown" does not work. (unless (memq system-type '(ms-dos windows-nt)) (let ((uid (or (and (natnump uid) uid) (tramp-get-local-uid 'integer))) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 643e19c1d2d..fa5a614fbf4 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4474,7 +4474,9 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (let ((tmp-name (tramp--test-make-temp-name nil quoted))) (unwind-protect (progn - (load tmp-name 'noerror 'nomessage) + ;; Ange-FTP does not tolerate a missing file, even with `noerror'. + (unless (tramp--test-ange-ftp-p) + (load tmp-name 'noerror 'nomessage)) (should-not (featurep 'tramp-test-load)) (write-region "(provide 'tramp-test-load)" nil tmp-name) ;; `load' in lread.c does not pass `must-suffix'. Why?