aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2025-04-05 07:07:29 -0400
committerEli Zaretskii2025-04-05 07:07:29 -0400
commit54b485ced60448bd4d546593b35ae0fb34ead552 (patch)
tree0bc100ce11aa29f66152c6dbbdb9e8a1fd571957
parent971f41fd668556a26824bdf5d6f847f6e708a8e8 (diff)
parent99d70ce6c265744b21e1ffe6c034ded833917139 (diff)
downloademacs-54b485ced60448bd4d546593b35ae0fb34ead552.tar.gz
emacs-54b485ced60448bd4d546593b35ae0fb34ead552.zip
Merge from origin/emacs-30
99d70ce6c26 Fix Tramp problem with loooongish file names
-rw-r--r--lisp/net/tramp-sh.el93
1 files changed, 51 insertions, 42 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 047d93a51b8..63d5332faf2 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -648,6 +648,14 @@ we have this shell function.
648Format specifiers are replaced by `tramp-expand-script', percent 648Format specifiers are replaced by `tramp-expand-script', percent
649characters need to be doubled.") 649characters need to be doubled.")
650 650
651(defconst tramp-readlink-file-truename
652 "if %m -h \"$1\"; then echo t; else echo nil; fi
653%r \"$1\""
654 "Shell script to produce output suitable for use with `file-truename'
655on the remote file system.
656Format specifiers are replaced by `tramp-expand-script', percent
657characters need to be doubled.")
658
651(defconst tramp-perl-file-truename 659(defconst tramp-perl-file-truename
652 "%p -e ' 660 "%p -e '
653use File::Spec; 661use File::Spec;
@@ -1151,11 +1159,11 @@ characters need to be doubled.")
1151(defconst tramp-bundle-read-file-names 1159(defconst tramp-bundle-read-file-names
1152 "echo \"(\" 1160 "echo \"(\"
1153while read file; do 1161while read file; do
1154 quoted=`echo \"$file\" | sed -e \"s/\\\"/\\\\\\\\\\\\\\\\\\\"/\"` 1162 quoted=`echo \"$file\" | sed -e \"s/\\\"/\\\\\\\\\\\\\\\\\\\"/\"`
1155 printf \"(%%b\" \"\\\"$quoted\\\"\" 1163 printf \"(%%b\" \"\\\"$quoted\\\"\"
1156 if %s \"$file\"; then printf \" %%b\" t; else printf \" %%b\" nil; fi 1164 if %q \"$file\"; then printf \" %%b\" t; else printf \" %%b\" nil; fi
1157 if %s \"$file\"; then printf \" %%b\" t; else printf \" %%b\" nil; fi 1165 if %m -r \"$file\"; then printf \" %%b\" t; else printf \" %%b\" nil; fi
1158 if %s \"$file\"; then printf \" %%b)\n\" t; else printf \" %%b)\n\" nil; fi 1166 if %m -d \"$file\"; then printf \" %%b)\n\" t; else printf \" %%b)\n\" nil; fi
1159done 1167done
1160echo \")\"" 1168echo \")\""
1161 "Script to check file attributes of a bundle of files. 1169 "Script to check file attributes of a bundle of files.
@@ -1291,18 +1299,15 @@ Operations not mentioned here will be handled by the normal Emacs functions.")
1291 (cond 1299 (cond
1292 ;; Use GNU readlink --canonicalize-missing where available. 1300 ;; Use GNU readlink --canonicalize-missing where available.
1293 ((tramp-get-remote-readlink v) 1301 ((tramp-get-remote-readlink v)
1302 (tramp-maybe-send-script
1303 v tramp-readlink-file-truename "tramp_readlink_file_truename")
1294 (tramp-send-command-and-check 1304 (tramp-send-command-and-check
1295 v (format 1305 v (format "tramp_readlink_file_truename %s"
1296 (concat 1306 (tramp-shell-quote-argument localname)))
1297 "(if %s -h \"%s\"; then echo t; else echo nil; fi) && "
1298 "%s --canonicalize-missing %s")
1299 (tramp-get-test-command v)
1300 (tramp-shell-quote-argument localname)
1301 (tramp-get-remote-readlink v)
1302 (tramp-shell-quote-argument localname)))
1303 (with-current-buffer (tramp-get-connection-buffer v) 1307 (with-current-buffer (tramp-get-connection-buffer v)
1304 (goto-char (point-min)) 1308 (goto-char (point-min))
1305 (tramp-set-file-property v localname "file-symlink-marker" (read (current-buffer))) 1309 (tramp-set-file-property
1310 v localname "file-symlink-marker" (read (current-buffer)))
1306 ;; We cannot call `read', the file name isn't quoted. 1311 ;; We cannot call `read', the file name isn't quoted.
1307 (forward-line) 1312 (forward-line)
1308 (buffer-substring (point) (line-end-position)))) 1313 (buffer-substring (point) (line-end-position))))
@@ -1318,7 +1323,8 @@ Operations not mentioned here will be handled by the normal Emacs functions.")
1318 (tramp-shell-quote-argument localname))) 1323 (tramp-shell-quote-argument localname)))
1319 (with-current-buffer (tramp-get-connection-buffer v) 1324 (with-current-buffer (tramp-get-connection-buffer v)
1320 (goto-char (point-min)) 1325 (goto-char (point-min))
1321 (tramp-set-file-property v localname "file-symlink-marker" (read (current-buffer))) 1326 (tramp-set-file-property
1327 v localname "file-symlink-marker" (read (current-buffer)))
1322 (read (current-buffer)))) 1328 (read (current-buffer))))
1323 1329
1324 ;; Do it yourself. 1330 ;; Do it yourself.
@@ -3594,12 +3600,7 @@ FILES must be the local names only. The cache attributes to be
3594filled are described in `tramp-bundle-read-file-names'." 3600filled are described in `tramp-bundle-read-file-names'."
3595 (when files 3601 (when files
3596 (tramp-maybe-send-script 3602 (tramp-maybe-send-script
3597 vec 3603 vec tramp-bundle-read-file-names "tramp_bundle_read_file_names")
3598 (format tramp-bundle-read-file-names
3599 (tramp-get-file-exists-command vec)
3600 (format "%s -r" (tramp-get-test-command vec))
3601 (format "%s -d" (tramp-get-test-command vec)))
3602 "tramp_bundle_read_file_names")
3603 3604
3604 (dolist 3605 (dolist
3605 (elt 3606 (elt
@@ -3982,14 +3983,15 @@ Fall back to normal file name handler if no Tramp handler exists."
3982 3983
3983(defun tramp-expand-script (vec script) 3984(defun tramp-expand-script (vec script)
3984 "Expand SCRIPT with remote files or commands. 3985 "Expand SCRIPT with remote files or commands.
3985\"%a\", \"%h\", \"%l\", \"%o\", \"%p\", \"%r\", \"%s\" and \"%y\" 3986\"%a\", \"%h\", \"%l\", \"%m\", \"%o\", \"%p\", \"%q\", \"%r\", \"%s\"
3986format specifiers are replaced by the respective `awk', 3987and \"%y\" format specifiers are replaced by the respective `awk',
3987`hexdump', `ls', `od', `perl', `readlink', `stat' and `python' 3988`hexdump', `ls', `test', od', `perl', `test -e', `readlink', `stat' and
3988commands. \"%n\" is replaced by \"2>/dev/null\", and \"%t\" is 3989`python' commands. \"%n\" is replaced by \"2>/dev/null\", and \"%t\" is
3989replaced by a temporary file name. If VEC is nil, the respective 3990replaced by a temporary file name. If VEC is nil, the respective local
3990local commands are used. If there is a format specifier which 3991commands are used. If there is a format specifier which cannot be
3991cannot be expanded, this function returns nil." 3992expanded, this function returns nil."
3992 (if (not (string-match-p (rx (| bol (not "%")) "%" (any "ahlnoprsty")) script)) 3993 (if (not (string-match-p
3994 (rx (| bol (not "%")) "%" (any "ahlmnopqrsty")) script))
3993 script 3995 script
3994 (catch 'wont-work 3996 (catch 'wont-work
3995 (let ((awk (when (string-match-p (rx (| bol (not "%")) "%a") script) 3997 (let ((awk (when (string-match-p (rx (| bol (not "%")) "%a") script)
@@ -4012,6 +4014,12 @@ cannot be expanded, this function returns nil."
4012 (or (tramp-get-ls-command vec) 4014 (or (tramp-get-ls-command vec)
4013 (throw 'wont-work nil)) 4015 (throw 'wont-work nil))
4014 (tramp-sh--quoting-style-options vec)))) 4016 (tramp-sh--quoting-style-options vec))))
4017 (test (when (string-match-p (rx (| bol (not "%")) "%m") script)
4018 (or (tramp-get-test-command vec)
4019 (throw 'wont-work nil))))
4020 (test-e (when (string-match-p (rx (| bol (not "%")) "%q") script)
4021 (or (tramp-get-file-exists-command vec)
4022 (throw 'wont-work nil))))
4015 (od (when (string-match-p (rx (| bol (not "%")) "%o") script) 4023 (od (when (string-match-p (rx (| bol (not "%")) "%o") script)
4016 (or (if vec (tramp-get-remote-od vec) (executable-find "od")) 4024 (or (if vec (tramp-get-remote-od vec) (executable-find "od"))
4017 (throw 'wont-work nil)))) 4025 (throw 'wont-work nil))))
@@ -4027,11 +4035,13 @@ cannot be expanded, this function returns nil."
4027 (executable-find "python")) 4035 (executable-find "python"))
4028 (throw 'wont-work nil)))) 4036 (throw 'wont-work nil))))
4029 (readlink (when (string-match-p (rx (| bol (not "%")) "%r") script) 4037 (readlink (when (string-match-p (rx (| bol (not "%")) "%r") script)
4030 (or 4038 (format "%s %s"
4031 (if vec 4039 (or
4032 (tramp-get-remote-readlink vec) 4040 (if vec
4033 (executable-find "readlink")) 4041 (tramp-get-remote-readlink vec)
4034 (throw 'wont-work nil)))) 4042 (executable-find "readlink"))
4043 (throw 'wont-work nil))
4044 "--canonicalize-missing")))
4035 (stat (when (string-match-p (rx (| bol (not "%")) "%s") script) 4045 (stat (when (string-match-p (rx (| bol (not "%")) "%s") script)
4036 (or 4046 (or
4037 (if vec 4047 (if vec
@@ -4046,8 +4056,8 @@ cannot be expanded, this function returns nil."
4046 (format-spec 4056 (format-spec
4047 script 4057 script
4048 (format-spec-make 4058 (format-spec-make
4049 ?a awk ?h hdmp ?l ls ?n dev ?o od ?p perl 4059 ?a awk ?h hdmp ?l ls ?m test ?n dev ?o od ?p perl
4050 ?r readlink ?s stat ?t tmp ?y python)))))) 4060 ?q test-e ?r readlink ?s stat ?t tmp ?y python))))))
4051 4061
4052(defun tramp-maybe-send-script (vec script name) 4062(defun tramp-maybe-send-script (vec script name)
4053 "Define in remote shell function NAME implemented as SCRIPT. 4063 "Define in remote shell function NAME implemented as SCRIPT.
@@ -5828,12 +5838,11 @@ Nonexistent directories are removed from spec."
5828 "Determine remote `readlink' command." 5838 "Determine remote `readlink' command."
5829 (with-tramp-connection-property vec "readlink" 5839 (with-tramp-connection-property vec "readlink"
5830 (tramp-message vec 5 "Finding a suitable `readlink' command") 5840 (tramp-message vec 5 "Finding a suitable `readlink' command")
5831 (let ((result (tramp-find-executable 5841 (when-let* ((result (tramp-find-executable
5832 vec "readlink" (tramp-get-remote-path vec)))) 5842 vec "readlink" (tramp-get-remote-path vec)))
5833 (when (and result 5843 ((tramp-send-command-and-check
5834 (tramp-send-command-and-check 5844 vec (format "%s --canonicalize-missing /" result))))
5835 vec (format "%s --canonicalize-missing /" result))) 5845 result)))
5836 result))))
5837 5846
5838(defun tramp-get-remote-touch (vec) 5847(defun tramp-get-remote-touch (vec)
5839 "Determine remote `touch' command." 5848 "Determine remote `touch' command."