diff options
| author | Michael Albinus | 2015-03-24 20:05:00 +0100 |
|---|---|---|
| committer | Michael Albinus | 2015-03-24 20:05:00 +0100 |
| commit | 444975fa5493b962851b9a01749c22c99d2b0992 (patch) | |
| tree | 731f99b3c4ebee6f7e3d246fa8cde1e92d01bed9 | |
| parent | 711770da9101a94ada42881cb86a976d323e9348 (diff) | |
| download | emacs-444975fa5493b962851b9a01749c22c99d2b0992.tar.gz emacs-444975fa5493b962851b9a01749c22c99d2b0992.zip | |
Improve special char handling in Tramp
* net/tramp-sh.el (tramp-do-file-attributes-with-ls)
(tramp-do-file-attributes-with-stat): Quote file names in output.
(tramp-do-directory-files-and-attributes-with-stat): Use "//" as marker.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 51 |
2 files changed, 37 insertions, 20 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e91d2bc0464..3b8fa7d66c7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2015-03-24 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * net/tramp-sh.el (tramp-do-file-attributes-with-ls) | ||
| 4 | (tramp-do-file-attributes-with-stat): Quote file names in output. | ||
| 5 | (tramp-do-directory-files-and-attributes-with-stat): Use "//" as marker. | ||
| 6 | |||
| 1 | 2015-03-24 Daiki Ueno <ueno@gnu.org> | 7 | 2015-03-24 Daiki Ueno <ueno@gnu.org> |
| 2 | 8 | ||
| 3 | * epg.el (epg-start-generate-key): Fix typo in "gpg --gen-key" | 9 | * epg.el (epg-start-generate-key): Fix typo in "gpg --gen-key" |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index b82b4deb21a..f59c5fbdf67 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -1175,15 +1175,19 @@ target of the symlink differ." | |||
| 1175 | (tramp-message vec 5 "file attributes with ls: %s" localname) | 1175 | (tramp-message vec 5 "file attributes with ls: %s" localname) |
| 1176 | (tramp-send-command | 1176 | (tramp-send-command |
| 1177 | vec | 1177 | vec |
| 1178 | (format "(%s %s || %s -h %s) && %s %s %s" | 1178 | (format "(%s %s || %s -h %s) && %s %s %s %s" |
| 1179 | (tramp-get-file-exists-command vec) | 1179 | (tramp-get-file-exists-command vec) |
| 1180 | (tramp-shell-quote-argument localname) | 1180 | (tramp-shell-quote-argument localname) |
| 1181 | (tramp-get-test-command vec) | 1181 | (tramp-get-test-command vec) |
| 1182 | (tramp-shell-quote-argument localname) | 1182 | (tramp-shell-quote-argument localname) |
| 1183 | (tramp-get-ls-command vec) | 1183 | (tramp-get-ls-command vec) |
| 1184 | ;; On systems which have no quoting style, file names | ||
| 1185 | ;; with special characters could fail. | ||
| 1186 | (if (tramp-get-ls-command-with-quoting-style vec) | ||
| 1187 | "--quoting-style=c" "") | ||
| 1184 | (if (eq id-format 'integer) "-ildn" "-ild") | 1188 | (if (eq id-format 'integer) "-ildn" "-ild") |
| 1185 | (tramp-shell-quote-argument localname))) | 1189 | (tramp-shell-quote-argument localname))) |
| 1186 | ;; parse `ls -l' output ... | 1190 | ;; Parse `ls -l' output ... |
| 1187 | (with-current-buffer (tramp-get-buffer vec) | 1191 | (with-current-buffer (tramp-get-buffer vec) |
| 1188 | (when (> (buffer-size) 0) | 1192 | (when (> (buffer-size) 0) |
| 1189 | (goto-char (point-min)) | 1193 | (goto-char (point-min)) |
| @@ -1222,11 +1226,14 @@ target of the symlink differ." | |||
| 1222 | ;; From the file modes, figure out other stuff. | 1226 | ;; From the file modes, figure out other stuff. |
| 1223 | (setq symlinkp (eq ?l (aref res-filemodes 0))) | 1227 | (setq symlinkp (eq ?l (aref res-filemodes 0))) |
| 1224 | (setq dirp (eq ?d (aref res-filemodes 0))) | 1228 | (setq dirp (eq ?d (aref res-filemodes 0))) |
| 1225 | ;; if symlink, find out file name pointed to | 1229 | ;; If symlink, find out file name pointed to. |
| 1226 | (when symlinkp | 1230 | (when symlinkp |
| 1227 | (search-forward "-> ") | 1231 | (search-forward "-> ") |
| 1228 | (setq res-symlink-target (buffer-substring (point) (point-at-eol)))) | 1232 | (setq res-symlink-target |
| 1229 | ;; return data gathered | 1233 | (if (tramp-get-ls-command-with-quoting-style vec) |
| 1234 | (read (current-buffer)) | ||
| 1235 | (buffer-substring (point) (point-at-eol))))) | ||
| 1236 | ;; Return data gathered. | ||
| 1230 | (list | 1237 | (list |
| 1231 | ;; 0. t for directory, string (name linked to) for symbolic | 1238 | ;; 0. t for directory, string (name linked to) for symbolic |
| 1232 | ;; link, or nil. | 1239 | ;; link, or nil. |
| @@ -1249,9 +1256,9 @@ target of the symlink differ." | |||
| 1249 | ;; 8. File modes, as a string of ten letters or dashes as in ls -l. | 1256 | ;; 8. File modes, as a string of ten letters or dashes as in ls -l. |
| 1250 | res-filemodes | 1257 | res-filemodes |
| 1251 | ;; 9. t if file's gid would change if file were deleted and | 1258 | ;; 9. t if file's gid would change if file were deleted and |
| 1252 | ;; recreated. Will be set in `tramp-convert-file-attributes' | 1259 | ;; recreated. Will be set in `tramp-convert-file-attributes'. |
| 1253 | t | 1260 | t |
| 1254 | ;; 10. inode number. | 1261 | ;; 10. Inode number. |
| 1255 | res-inode | 1262 | res-inode |
| 1256 | ;; 11. Device number. Will be replaced by a virtual device number. | 1263 | ;; 11. Device number. Will be replaced by a virtual device number. |
| 1257 | -1 | 1264 | -1 |
| @@ -1275,16 +1282,21 @@ target of the symlink differ." | |||
| 1275 | (tramp-send-command-and-read | 1282 | (tramp-send-command-and-read |
| 1276 | vec | 1283 | vec |
| 1277 | (format | 1284 | (format |
| 1278 | ;; On Opsware, pdksh (which is the true name of ksh there) doesn't | 1285 | (concat |
| 1279 | ;; parse correctly the sequence "((". Therefore, we add a space. | 1286 | ;; On Opsware, pdksh (which is the true name of ksh there) |
| 1280 | "( (%s %s || %s -h %s) && %s -c '((\"%%N\") %%h %s %s %%Xe0 %%Ye0 %%Ze0 %%se0 \"%%A\" t %%ie0 -1)' \"%s\" || echo nil)" | 1287 | ;; doesn't parse correctly the sequence "((". Therefore, we add |
| 1288 | ;; a space. Apostrophes in the stat output are masked as "//", | ||
| 1289 | ;; in order to make a proper shell escape of them in file names. | ||
| 1290 | "( (%s %s || %s -h %s) && (%s -c " | ||
| 1291 | "'((//%%N//) %%h %s %s %%Xe0 %%Ye0 %%Ze0 %%se0 //%%A// t %%ie0 -1)' " | ||
| 1292 | "%s | sed -e 's/\"/\\\\\"/g' -e 's/\\/\\//\"/g') || echo nil)") | ||
| 1281 | (tramp-get-file-exists-command vec) | 1293 | (tramp-get-file-exists-command vec) |
| 1282 | (tramp-shell-quote-argument localname) | 1294 | (tramp-shell-quote-argument localname) |
| 1283 | (tramp-get-test-command vec) | 1295 | (tramp-get-test-command vec) |
| 1284 | (tramp-shell-quote-argument localname) | 1296 | (tramp-shell-quote-argument localname) |
| 1285 | (tramp-get-remote-stat vec) | 1297 | (tramp-get-remote-stat vec) |
| 1286 | (if (eq id-format 'integer) "%ue0" "\"%U\"") | 1298 | (if (eq id-format 'integer) "%ue0" "//%U//") |
| 1287 | (if (eq id-format 'integer) "%ge0" "\"%G\"") | 1299 | (if (eq id-format 'integer) "%ge0" "//%G//") |
| 1288 | (tramp-shell-quote-argument localname)))) | 1300 | (tramp-shell-quote-argument localname)))) |
| 1289 | 1301 | ||
| 1290 | (defun tramp-sh-handle-set-visited-file-modtime (&optional time-list) | 1302 | (defun tramp-sh-handle-set-visited-file-modtime (&optional time-list) |
| @@ -1717,14 +1729,13 @@ be non-negative integers." | |||
| 1717 | (concat | 1729 | (concat |
| 1718 | ;; We must care about file names with spaces, or starting with | 1730 | ;; We must care about file names with spaces, or starting with |
| 1719 | ;; "-"; this would confuse xargs. "ls -aQ" might be a solution, | 1731 | ;; "-"; this would confuse xargs. "ls -aQ" might be a solution, |
| 1720 | ;; but it does not work on all remote systems. Therefore, we | 1732 | ;; but it does not work on all remote systems. Apostrophes in |
| 1721 | ;; use \000 as file separator. | 1733 | ;; the stat output are masked as "//", in order to make a proper |
| 1722 | ;; Apostrophes in the stat output are masked as ?/ characters, in | 1734 | ;; shell escape of them in file names. |
| 1723 | ;; order to make a proper shell escape of them in file names. | ||
| 1724 | "cd %s && echo \"(\"; (%s %s -a | " | 1735 | "cd %s && echo \"(\"; (%s %s -a | " |
| 1725 | "xargs %s -c " | 1736 | "xargs %s -c " |
| 1726 | "'(/%%n/ (/%%N/) %%h %s %s %%Xe0 %%Ye0 %%Ze0 %%se0 /%%A/ t %%ie0 -1)' " | 1737 | "'(//%%n// (//%%N//) %%h %s %s %%Xe0 %%Ye0 %%Ze0 %%se0 //%%A// t %%ie0 -1)' " |
| 1727 | "-- 2>/dev/null | sed -e 's/\"/\\\\\"/g' -e 's/\\//\"/g'); echo \")\"") | 1738 | "-- 2>/dev/null | sed -e 's/\"/\\\\\"/g' -e 's/\\/\\//\"/g'); echo \")\"") |
| 1728 | (tramp-shell-quote-argument localname) | 1739 | (tramp-shell-quote-argument localname) |
| 1729 | (tramp-get-ls-command vec) | 1740 | (tramp-get-ls-command vec) |
| 1730 | ;; On systems which have no quoting style, file names with | 1741 | ;; On systems which have no quoting style, file names with |
| @@ -1732,8 +1743,8 @@ be non-negative integers." | |||
| 1732 | (if (tramp-get-ls-command-with-quoting-style vec) | 1743 | (if (tramp-get-ls-command-with-quoting-style vec) |
| 1733 | "--quoting-style=shell" "") | 1744 | "--quoting-style=shell" "") |
| 1734 | (tramp-get-remote-stat vec) | 1745 | (tramp-get-remote-stat vec) |
| 1735 | (if (eq id-format 'integer) "%ue0" "/%U/") | 1746 | (if (eq id-format 'integer) "%ue0" "//%U//") |
| 1736 | (if (eq id-format 'integer) "%ge0" "/%G/")))) | 1747 | (if (eq id-format 'integer) "%ge0" "//%G//")))) |
| 1737 | 1748 | ||
| 1738 | ;; This function should return "foo/" for directories and "bar" for | 1749 | ;; This function should return "foo/" for directories and "bar" for |
| 1739 | ;; files. | 1750 | ;; files. |