From: Michael Albinus Date: Sat, 15 Oct 2022 16:21:13 +0000 (+0200) Subject: Minor Tramp fixes X-Git-Tag: emacs-29.0.90~1616^2~600 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=215f65d1dcb70f29fa4919f5581d28ad27ba4db2;p=emacs.git Minor Tramp fixes * lisp/net/tramp-sh.el (tramp-perl-id): Fix Perl script. (tramp-sh-handle-expand-file-name): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-expand-file-name): Check, that there's really a Tramp file name. --- diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 3240f5352a7..d74afc84126 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -789,8 +789,8 @@ use strict; use warnings; use POSIX qw(getgroups); -my ($user, $passwd, $uid, $gid) = getpwuid $< ; -my $group = getgrgid $gid ; +my ( $uid, $user ) = ( $>, scalar getpwuid $> ); +my ( $gid, $group ) = ( $), scalar getgrgid $) ); my @groups = map { $_ . \"(\" . getgrgid ($_) . \")\" } getgroups (); printf \"uid=%%d(%%s) gid=%%d(%%s) groups=%%s\\n\", @@ -2827,11 +2827,14 @@ the result will be a local, non-Tramp, file name." ;; Handle empty NAME. (when (zerop (length name)) (setq name ".")) ;; On MS Windows, some special file names are not returned properly - ;; by `file-name-absolute-p'. - (if (and (eq system-type 'windows-nt) - (string-match-p - (tramp-compat-rx bol (| (: alpha ":") (: (literal null-device) eol))) - name)) + ;; by `file-name-absolute-p'. If `tramp-syntax' is `simplified', + ;; there could be the falso positive "/:". + (if (or (and (eq system-type 'windows-nt) + (string-match-p + (tramp-compat-rx bol (| (: alpha ":") (: (literal null-device) eol))) + name)) + (and (not (tramp-tramp-file-p name)) + (not (tramp-tramp-file-p dir)))) (tramp-run-real-handler #'expand-file-name (list name dir)) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index dc87c590b3b..bc8739c4d6c 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el @@ -369,33 +369,36 @@ the result will be a local, non-Tramp, file name." ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) (setq name (tramp-compat-file-name-concat dir name))) - (with-parsed-tramp-file-name name nil - ;; Tilde expansion if necessary. We cannot accept "~/", because - ;; under sudo "~/" is expanded to the local user home directory - ;; but to the root home directory. - (when (zerop (length localname)) - (setq localname "~")) - (unless (file-name-absolute-p localname) - (setq localname (format "~%s/%s" user localname))) - (when (string-match - (tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) eos) - localname) - (let ((uname (match-string 1 localname)) - (fname (match-string 2 localname)) - hname) - (when (zerop (length uname)) - (setq uname user)) - (when (setq hname (tramp-get-home-directory v uname)) - (setq localname (concat hname fname))))) - ;; Do not keep "/..". - (when (string-match-p (rx bos "/" (** 1 2 ".") eos) localname) - (setq localname "/")) - ;; Do normal `expand-file-name' (this does "~user/", "/./" and "/../"). - (tramp-make-tramp-file-name - v (if (string-prefix-p "~" localname) - localname - (tramp-run-real-handler - #'expand-file-name (list localname)))))) + ;; If NAME is not a Tramp file, run the real handler. + (if (not (tramp-tramp-file-p name)) + (tramp-run-real-handler #'expand-file-name (list name)) + (with-parsed-tramp-file-name name nil + ;; Tilde expansion if necessary. We cannot accept "~/", because + ;; under sudo "~/" is expanded to the local user home directory + ;; but to the root home directory. + (when (zerop (length localname)) + (setq localname "~")) + (unless (file-name-absolute-p localname) + (setq localname (format "~%s/%s" user localname))) + (when (string-match + (tramp-compat-rx bos "~" (group (* (not "/"))) (group (* nonl)) eos) + localname) + (let ((uname (match-string 1 localname)) + (fname (match-string 2 localname)) + hname) + (when (zerop (length uname)) + (setq uname user)) + (when (setq hname (tramp-get-home-directory v uname)) + (setq localname (concat hname fname))))) + ;; Do not keep "/..". + (when (string-match-p (rx bos "/" (** 1 2 ".") eos) localname) + (setq localname "/")) + ;; Do normal `expand-file-name' (this does "~user/", "/./" and "/../"). + (tramp-make-tramp-file-name + v (if (string-prefix-p "~" localname) + localname + (tramp-run-real-handler + #'expand-file-name (list localname))))))) (defun tramp-sudoedit-remote-acl-p (vec) "Check, whether ACL is enabled on the remote host."