diff options
| author | Michael Albinus | 2023-08-15 15:23:20 +0200 |
|---|---|---|
| committer | Michael Albinus | 2023-08-15 15:23:20 +0200 |
| commit | 5c101b1adac2b4f3cc4e08a6492b406952c529f3 (patch) | |
| tree | 0485973cef195d938b90d0a967a21bef0c6a798d | |
| parent | 425c998a1117da6ebbd1489ad2aa3f7e2f8bd594 (diff) | |
| download | emacs-5c101b1adac2b4f3cc4e08a6492b406952c529f3.tar.gz emacs-5c101b1adac2b4f3cc4e08a6492b406952c529f3.zip | |
Some Tramp optimizations
* lisp/net/tramp-sh.el (tramp-perl-file-name-all-completions):
Extend. It shall return also some basic file attributes.
(tramp-bundle-read-file-names): Simplify data to be transferred.
(tramp-sh-handle-file-name-all-completions): Read additional attributes.
(tramp-sh-handle-expand-file-name): Check also "doas".
(tramp-bundle-read-file-names): Handle changed data layout.
(tramp-find-file-exists-command): Set "file-exists-p" file property.
| -rw-r--r-- | lisp/net/tramp-sh.el | 122 |
1 files changed, 65 insertions, 57 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index d836fb1f387..426682ddef1 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -634,16 +634,20 @@ characters need to be doubled.") | |||
| 634 | 634 | ||
| 635 | (defconst tramp-perl-file-name-all-completions | 635 | (defconst tramp-perl-file-name-all-completions |
| 636 | "%p -e ' | 636 | "%p -e ' |
| 637 | opendir(d, $ARGV[0]) || die(\"$ARGV[0]: $!\\nfail\\n\"); | 637 | ($dir = $ARGV[0]) =~ s#/+$##; |
| 638 | opendir(d, $dir) || die(\"$dir: $!\\nfail\\n\"); | ||
| 638 | @files = readdir(d); closedir(d); | 639 | @files = readdir(d); closedir(d); |
| 640 | print \"(\\n\"; | ||
| 639 | foreach $f (@files) { | 641 | foreach $f (@files) { |
| 640 | if (-d \"$ARGV[0]/$f\") { | 642 | ($p = $f) =~ s/\\\"/\\\\\\\"/g; |
| 641 | print \"$f/\\n\"; | 643 | ($q = \"$dir/$f\") =~ s/\\\"/\\\\\\\"/g; |
| 642 | } | 644 | print \"(\", |
| 643 | else { | 645 | ((-d \"$q\") ? \"\\\"$p/\\\" \\\"$q\\\" t\" : \"\\\"$p\\\" \\\"$q\\\" nil\"), |
| 644 | print \"$f\\n\"; | 646 | ((-e \"$q\") ? \" t\" : \" nil\"), |
| 645 | } | 647 | ((-r \"$q\") ? \" t\" : \" nil\"), |
| 648 | \")\\n\"; | ||
| 646 | } | 649 | } |
| 650 | print \")\\n\"; | ||
| 647 | ' \"$1\" %n" | 651 | ' \"$1\" %n" |
| 648 | "Perl script to produce output suitable for use with | 652 | "Perl script to produce output suitable for use with |
| 649 | `file-name-all-completions' on the remote file system. | 653 | `file-name-all-completions' on the remote file system. |
| @@ -1073,21 +1077,10 @@ characters need to be doubled.") | |||
| 1073 | "echo \"(\" | 1077 | "echo \"(\" |
| 1074 | while read file; do | 1078 | while read file; do |
| 1075 | quoted=`echo \"$file\" | sed -e \"s/\\\"/\\\\\\\\\\\\\\\\\\\"/\"` | 1079 | quoted=`echo \"$file\" | sed -e \"s/\\\"/\\\\\\\\\\\\\\\\\\\"/\"` |
| 1076 | if %s \"$file\"; then | 1080 | echo -n \"(\\\"$quoted\\\"\" |
| 1077 | echo \"(\\\"$quoted\\\" \\\"file-exists-p\\\" t)\" | 1081 | if %s \"$file\"; then echo -n \" t\"; else echo -n \" nil\"; fi |
| 1078 | else | 1082 | if %s \"$file\"; then echo -n \" t\"; else echo -n \" nil\"; fi |
| 1079 | echo \"(\\\"$quoted\\\" \\\"file-exists-p\\\" nil)\" | 1083 | if %s \"$file\"; then echo \" t)\"; else echo \" nil)\"; fi |
| 1080 | fi | ||
| 1081 | if %s \"$file\"; then | ||
| 1082 | echo \"(\\\"$quoted\\\" \\\"file-readable-p\\\" t)\" | ||
| 1083 | else | ||
| 1084 | echo \"(\\\"$quoted\\\" \\\"file-readable-p\\\" nil)\" | ||
| 1085 | fi | ||
| 1086 | if %s \"$file\"; then | ||
| 1087 | echo \"(\\\"$quoted\\\" \\\"file-directory-p\\\" t)\" | ||
| 1088 | else | ||
| 1089 | echo \"(\\\"$quoted\\\" \\\"file-directory-p\\\" nil)\" | ||
| 1090 | fi | ||
| 1091 | done | 1084 | done |
| 1092 | echo \")\"" | 1085 | echo \")\"" |
| 1093 | "Script to check file attributes of a bundle of files. | 1086 | "Script to check file attributes of a bundle of files. |
| @@ -1870,34 +1863,48 @@ ID-FORMAT valid values are `string' and `integer'." | |||
| 1870 | ;; Get a list of directories and files, including | 1863 | ;; Get a list of directories and files, including |
| 1871 | ;; reliably tagging the directories with a trailing "/". | 1864 | ;; reliably tagging the directories with a trailing "/". |
| 1872 | ;; Because I rock. --daniel@danann.net | 1865 | ;; Because I rock. --daniel@danann.net |
| 1873 | (when (tramp-send-command-and-check | 1866 | (if (tramp-get-remote-perl v) |
| 1874 | v | 1867 | (progn |
| 1875 | (if (tramp-get-remote-perl v) | 1868 | (tramp-maybe-send-script |
| 1876 | (progn | 1869 | v tramp-perl-file-name-all-completions |
| 1877 | (tramp-maybe-send-script | 1870 | "tramp_perl_file_name_all_completions") |
| 1878 | v tramp-perl-file-name-all-completions | 1871 | (setq result |
| 1879 | "tramp_perl_file_name_all_completions") | 1872 | (tramp-send-command-and-read |
| 1880 | (format "tramp_perl_file_name_all_completions %s" | 1873 | v (format "tramp_perl_file_name_all_completions %s" |
| 1881 | (tramp-shell-quote-argument localname))) | 1874 | (tramp-shell-quote-argument localname)) |
| 1882 | 1875 | 'noerror)) | |
| 1883 | (format (concat | 1876 | ;; Cached values. |
| 1884 | "cd %s 2>&1 && %s -a 2>%s" | 1877 | (dolist (elt result) |
| 1885 | " | while IFS= read f; do" | 1878 | (tramp-set-file-property |
| 1886 | " if %s -d \"$f\" 2>%s;" | 1879 | v (cadr elt) "file-directory-p" (nth 2 elt)) |
| 1887 | " then echo \"$f/\"; else echo \"$f\"; fi;" | 1880 | (tramp-set-file-property |
| 1888 | " done") | 1881 | v (cadr elt) "file-exists-p" (nth 3 elt)) |
| 1889 | (tramp-shell-quote-argument localname) | 1882 | (tramp-set-file-property |
| 1890 | (tramp-get-ls-command v) | 1883 | v (cadr elt) "file-readable-p" (nth 4 elt))) |
| 1891 | (tramp-get-remote-null-device v) | 1884 | ;; Result. |
| 1892 | (tramp-get-test-command v) | 1885 | (mapcar #'car result)) |
| 1893 | (tramp-get-remote-null-device v)))) | 1886 | |
| 1894 | 1887 | ;; Do it with ls. | |
| 1895 | ;; Now grab the output. | 1888 | (when (tramp-send-command-and-check |
| 1896 | (with-current-buffer (tramp-get-buffer v) | 1889 | v (format (concat |
| 1897 | (goto-char (point-max)) | 1890 | "cd %s 2>&1 && %s -a 2>%s" |
| 1898 | (while (zerop (forward-line -1)) | 1891 | " | while IFS= read f; do" |
| 1899 | (push (buffer-substring (point) (line-end-position)) result))) | 1892 | " if %s -d \"$f\" 2>%s;" |
| 1900 | result))))))))) | 1893 | " then echo \"$f/\"; else echo \"$f\"; fi;" |
| 1894 | " done") | ||
| 1895 | (tramp-shell-quote-argument localname) | ||
| 1896 | (tramp-get-ls-command v) | ||
| 1897 | (tramp-get-remote-null-device v) | ||
| 1898 | (tramp-get-test-command v) | ||
| 1899 | (tramp-get-remote-null-device v))) | ||
| 1900 | |||
| 1901 | ;; Now grab the output. | ||
| 1902 | (with-current-buffer (tramp-get-buffer v) | ||
| 1903 | (goto-char (point-max)) | ||
| 1904 | (while (zerop (forward-line -1)) | ||
| 1905 | (push | ||
| 1906 | (buffer-substring (point) (line-end-position)) result))) | ||
| 1907 | result)))))))))) | ||
| 1901 | 1908 | ||
| 1902 | ;; cp, mv and ln | 1909 | ;; cp, mv and ln |
| 1903 | 1910 | ||
| @@ -2842,7 +2849,8 @@ the result will be a local, non-Tramp, file name." | |||
| 2842 | ;; appropriate either, because ssh and companions might | 2849 | ;; appropriate either, because ssh and companions might |
| 2843 | ;; use a user name from the config file. | 2850 | ;; use a user name from the config file. |
| 2844 | (when (and (tramp-string-empty-or-nil-p uname) | 2851 | (when (and (tramp-string-empty-or-nil-p uname) |
| 2845 | (string-match-p (rx bos "su" (? "do") eos) method)) | 2852 | (string-match-p |
| 2853 | (rx bos (| "su" "sudo" "doas" "ksu") eos) method)) | ||
| 2846 | (setq uname user)) | 2854 | (setq uname user)) |
| 2847 | (when (setq hname (tramp-get-home-directory v uname)) | 2855 | (when (setq hname (tramp-get-home-directory v uname)) |
| 2848 | (setq localname (concat hname fname))))) | 2856 | (setq localname (concat hname fname))))) |
| @@ -3630,17 +3638,16 @@ filled are described in `tramp-bundle-read-file-names'." | |||
| 3630 | (format | 3638 | (format |
| 3631 | "tramp_bundle_read_file_names <<'%s'\n%s\n%s\n" | 3639 | "tramp_bundle_read_file_names <<'%s'\n%s\n%s\n" |
| 3632 | tramp-end-of-heredoc | 3640 | tramp-end-of-heredoc |
| 3633 | (mapconcat #'tramp-shell-quote-argument | 3641 | (mapconcat #'tramp-shell-quote-argument files "\n") |
| 3634 | files | ||
| 3635 | "\n") | ||
| 3636 | tramp-end-of-heredoc)) | 3642 | tramp-end-of-heredoc)) |
| 3637 | (with-current-buffer (tramp-get-connection-buffer vec) | 3643 | (with-current-buffer (tramp-get-connection-buffer vec) |
| 3638 | ;; Read the expression. | 3644 | ;; Read the expression. |
| 3639 | (goto-char (point-min)) | 3645 | (goto-char (point-min)) |
| 3640 | (read (current-buffer))))) | 3646 | (read (current-buffer))))) |
| 3641 | 3647 | ||
| 3642 | (tramp-set-file-property | 3648 | (tramp-set-file-property vec (car elt) "file-exists-p" (nth 1 elt)) |
| 3643 | vec (car elt) (cadr elt) (cadr (cdr elt)))))) | 3649 | (tramp-set-file-property vec (car elt) "file-readable-p" (nth 2 elt)) |
| 3650 | (tramp-set-file-property vec (car elt) "file-directory-p" (nth 3 elt))))) | ||
| 3644 | 3651 | ||
| 3645 | (defvar tramp-vc-registered-file-names nil | 3652 | (defvar tramp-vc-registered-file-names nil |
| 3646 | "List used to collect file names, which are checked during `vc-registered'.") | 3653 | "List used to collect file names, which are checked during `vc-registered'.") |
| @@ -4256,6 +4263,7 @@ file exists and nonzero exit status otherwise." | |||
| 4256 | vec (format "%s %s" result nonexistent)))))) | 4263 | vec (format "%s %s" result nonexistent)))))) |
| 4257 | (tramp-error | 4264 | (tramp-error |
| 4258 | vec 'file-error "Couldn't find command to check if file exists")) | 4265 | vec 'file-error "Couldn't find command to check if file exists")) |
| 4266 | (tramp-set-file-property vec existing "file-exists-p" t) | ||
| 4259 | result)) | 4267 | result)) |
| 4260 | 4268 | ||
| 4261 | (defun tramp-get-sh-extra-args (shell) | 4269 | (defun tramp-get-sh-extra-args (shell) |
| @@ -5647,7 +5655,7 @@ Nonexistent directories are removed from spec." | |||
| 5647 | remote-path :test #'string-equal :from-end t)) | 5655 | remote-path :test #'string-equal :from-end t)) |
| 5648 | 5656 | ||
| 5649 | ;; Remove non-existing directories. | 5657 | ;; Remove non-existing directories. |
| 5650 | (let ((remote-file-name-inhibit-cache nil)) | 5658 | (let (remote-file-name-inhibit-cache) |
| 5651 | (tramp-bundle-read-file-names vec remote-path) | 5659 | (tramp-bundle-read-file-names vec remote-path) |
| 5652 | (cl-remove-if | 5660 | (cl-remove-if |
| 5653 | (lambda (x) (not (tramp-get-file-property vec x "file-directory-p"))) | 5661 | (lambda (x) (not (tramp-get-file-property vec x "file-directory-p"))) |