aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-01-10 13:07:21 +0100
committerMichael Albinus2016-01-10 13:07:21 +0100
commit1089dc98b778d1c6eb190dbd840d40c33aea9bea (patch)
treece78823183fe512907107c14558697cb38d65c81
parent684eb58db992dec56a05719732edc547fa77c1be (diff)
downloademacs-1089dc98b778d1c6eb190dbd840d40c33aea9bea.tar.gz
emacs-1089dc98b778d1c6eb190dbd840d40c33aea9bea.zip
Handle too long commands in Tramp
* lisp/net/tramp-sh.el (tramp-sh-handle-make-symbolic-link) (tramp-do-file-attributes-with-ls): Send sequence of commands, in order to not exceed shell command line limit. * test/automated/tramp-tests.el (tramp--test-darwin-p): Remove. (tramp--test-utf8): Include Arabic file name, again.
-rw-r--r--lisp/net/tramp-sh.el216
-rw-r--r--test/automated/tramp-tests.el10
2 files changed, 115 insertions, 111 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 1357db0ac42..7ace8864f88 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1100,15 +1100,19 @@ target of the symlink differ."
1100 ;; Right, they are on the same host, regardless of user, method, 1100 ;; Right, they are on the same host, regardless of user, method,
1101 ;; etc. We now make the link on the remote machine. This will 1101 ;; etc. We now make the link on the remote machine. This will
1102 ;; occur as the user that FILENAME belongs to. 1102 ;; occur as the user that FILENAME belongs to.
1103 (tramp-send-command-and-check 1103 (and (tramp-send-command-and-check
1104 l 1104 l (format "cd %s" (tramp-shell-quote-argument cwd)))
1105 (format 1105 (tramp-send-command-and-check
1106 "cd %s && %s -sf %s %s" 1106 l (format
1107 (tramp-shell-quote-argument cwd) 1107 "%s -sf %s %s"
1108 ln 1108 ln
1109 (tramp-shell-quote-argument filename) 1109 (tramp-shell-quote-argument filename)
1110 (tramp-shell-quote-argument l-localname)) 1110 ;; The command could exceed PATH_MAX, so we use
1111 t)))) 1111 ;; relative file names. However, relative file names
1112 ;; could start with "-". `tramp-shell-quote-argument'
1113 ;; does not handle this, we must do it ourselves.
1114 (tramp-shell-quote-argument
1115 (concat "./" (file-name-nondirectory l-localname)))))))))
1112 1116
1113(defun tramp-sh-handle-file-truename (filename) 1117(defun tramp-sh-handle-file-truename (filename)
1114 "Like `file-truename' for Tramp files." 1118 "Like `file-truename' for Tramp files."
@@ -1266,100 +1270,108 @@ target of the symlink differ."
1266 res-inode res-filemodes res-numlinks 1270 res-inode res-filemodes res-numlinks
1267 res-uid res-gid res-size res-symlink-target) 1271 res-uid res-gid res-size res-symlink-target)
1268 (tramp-message vec 5 "file attributes with ls: %s" localname) 1272 (tramp-message vec 5 "file attributes with ls: %s" localname)
1269 (tramp-send-command 1273 ;; We cannot send all three commands combined, it could exceed
1270 vec 1274 ;; NAME_MAX or PATH_MAX. Happened on Mac OS X, for example.
1271 (format "(%s %s || %s -h %s) && %s %s %s %s" 1275 (when (or (tramp-send-command-and-check
1272 (tramp-get-file-exists-command vec) 1276 vec
1273 (tramp-shell-quote-argument localname) 1277 (format "%s %s"
1274 (tramp-get-test-command vec) 1278 (tramp-get-file-exists-command vec)
1275 (tramp-shell-quote-argument localname) 1279 (tramp-shell-quote-argument localname)))
1276 (tramp-get-ls-command vec) 1280 (tramp-send-command-and-check
1277 (if (eq id-format 'integer) "-ildn" "-ild") 1281 vec
1278 ;; On systems which have no quoting style, file names 1282 (format "%s -h %s"
1279 ;; with special characters could fail. 1283 (tramp-get-test-command vec)
1280 (cond 1284 (tramp-shell-quote-argument localname))))
1281 ((tramp-get-ls-command-with-quoting-style vec) 1285 (tramp-send-command
1282 "--quoting-style=c") 1286 vec
1283 ((tramp-get-ls-command-with-w-option vec) 1287 (format "%s %s %s %s"
1284 "-w") 1288 (tramp-get-ls-command vec)
1285 (t "")) 1289 (if (eq id-format 'integer) "-ildn" "-ild")
1286 (tramp-shell-quote-argument localname))) 1290 ;; On systems which have no quoting style, file names
1287 ;; Parse `ls -l' output ... 1291 ;; with special characters could fail.
1288 (with-current-buffer (tramp-get-buffer vec) 1292 (cond
1289 (when (> (buffer-size) 0) 1293 ((tramp-get-ls-command-with-quoting-style vec)
1290 (goto-char (point-min)) 1294 "--quoting-style=c")
1291 ;; ... inode 1295 ((tramp-get-ls-command-with-w-option vec)
1292 (setq res-inode 1296 "-w")
1293 (condition-case err 1297 (t ""))
1294 (read (current-buffer)) 1298 (tramp-shell-quote-argument localname)))
1295 (invalid-read-syntax 1299 ;; Parse `ls -l' output ...
1296 (when (and (equal (cadr err) 1300 (with-current-buffer (tramp-get-buffer vec)
1297 "Integer constant overflow in reader") 1301 (when (> (buffer-size) 0)
1298 (string-match 1302 (goto-char (point-min))
1299 "^[0-9]+\\([0-9][0-9][0-9][0-9][0-9]\\)\\'" 1303 ;; ... inode
1300 (car (cddr err)))) 1304 (setq res-inode
1301 (let* ((big (read (substring (car (cddr err)) 0 1305 (condition-case err
1302 (match-beginning 1)))) 1306 (read (current-buffer))
1303 (small (read (match-string 1 (car (cddr err))))) 1307 (invalid-read-syntax
1304 (twiddle (/ small 65536))) 1308 (when (and (equal (cadr err)
1305 (cons (+ big twiddle) 1309 "Integer constant overflow in reader")
1306 (- small (* twiddle 65536)))))))) 1310 (string-match
1307 ;; ... file mode flags 1311 "^[0-9]+\\([0-9][0-9][0-9][0-9][0-9]\\)\\'"
1308 (setq res-filemodes (symbol-name (read (current-buffer)))) 1312 (car (cddr err))))
1309 ;; ... number links 1313 (let* ((big (read (substring (car (cddr err)) 0
1310 (setq res-numlinks (read (current-buffer))) 1314 (match-beginning 1))))
1311 ;; ... uid and gid 1315 (small (read (match-string 1 (car (cddr err)))))
1312 (setq res-uid (read (current-buffer))) 1316 (twiddle (/ small 65536)))
1313 (setq res-gid (read (current-buffer))) 1317 (cons (+ big twiddle)
1314 (if (eq id-format 'integer) 1318 (- small (* twiddle 65536))))))))
1319 ;; ... file mode flags
1320 (setq res-filemodes (symbol-name (read (current-buffer))))
1321 ;; ... number links
1322 (setq res-numlinks (read (current-buffer)))
1323 ;; ... uid and gid
1324 (setq res-uid (read (current-buffer)))
1325 (setq res-gid (read (current-buffer)))
1326 (if (eq id-format 'integer)
1327 (progn
1328 (unless (numberp res-uid) (setq res-uid -1))
1329 (unless (numberp res-gid) (setq res-gid -1)))
1315 (progn 1330 (progn
1316 (unless (numberp res-uid) (setq res-uid -1)) 1331 (unless (stringp res-uid) (setq res-uid (symbol-name res-uid)))
1317 (unless (numberp res-gid) (setq res-gid -1))) 1332 (unless (stringp res-gid) (setq res-gid (symbol-name res-gid)))))
1318 (progn 1333 ;; ... size
1319 (unless (stringp res-uid) (setq res-uid (symbol-name res-uid))) 1334 (setq res-size (read (current-buffer)))
1320 (unless (stringp res-gid) (setq res-gid (symbol-name res-gid))))) 1335 ;; From the file modes, figure out other stuff.
1321 ;; ... size 1336 (setq symlinkp (eq ?l (aref res-filemodes 0)))
1322 (setq res-size (read (current-buffer))) 1337 (setq dirp (eq ?d (aref res-filemodes 0)))
1323 ;; From the file modes, figure out other stuff. 1338 ;; If symlink, find out file name pointed to.
1324 (setq symlinkp (eq ?l (aref res-filemodes 0))) 1339 (when symlinkp
1325 (setq dirp (eq ?d (aref res-filemodes 0))) 1340 (search-forward "-> ")
1326 ;; If symlink, find out file name pointed to. 1341 (setq res-symlink-target
1327 (when symlinkp 1342 (if (tramp-get-ls-command-with-quoting-style vec)
1328 (search-forward "-> ") 1343 (read (current-buffer))
1329 (setq res-symlink-target 1344 (buffer-substring (point) (point-at-eol)))))
1330 (if (tramp-get-ls-command-with-quoting-style vec) 1345 ;; Return data gathered.
1331 (read (current-buffer)) 1346 (list
1332 (buffer-substring (point) (point-at-eol))))) 1347 ;; 0. t for directory, string (name linked to) for symbolic
1333 ;; Return data gathered. 1348 ;; link, or nil.
1334 (list 1349 (or dirp res-symlink-target)
1335 ;; 0. t for directory, string (name linked to) for symbolic 1350 ;; 1. Number of links to file.
1336 ;; link, or nil. 1351 res-numlinks
1337 (or dirp res-symlink-target) 1352 ;; 2. File uid.
1338 ;; 1. Number of links to file. 1353 res-uid
1339 res-numlinks 1354 ;; 3. File gid.
1340 ;; 2. File uid. 1355 res-gid
1341 res-uid 1356 ;; 4. Last access time, as a list of integers. Normally
1342 ;; 3. File gid. 1357 ;; this would be in the same format as `current-time', but
1343 res-gid 1358 ;; the subseconds part is not currently implemented, and (0
1344 ;; 4. Last access time, as a list of integers. Normally this 1359 ;; 0) denotes an unknown time.
1345 ;; would be in the same format as `current-time', but the 1360 ;; 5. Last modification time, likewise.
1346 ;; subseconds part is not currently implemented, and (0 0) 1361 ;; 6. Last status change time, likewise.
1347 ;; denotes an unknown time. 1362 '(0 0) '(0 0) '(0 0) ;CCC how to find out?
1348 ;; 5. Last modification time, likewise. 1363 ;; 7. Size in bytes (-1, if number is out of range).
1349 ;; 6. Last status change time, likewise. 1364 res-size
1350 '(0 0) '(0 0) '(0 0) ;CCC how to find out? 1365 ;; 8. File modes, as a string of ten letters or dashes as in ls -l.
1351 ;; 7. Size in bytes (-1, if number is out of range). 1366 res-filemodes
1352 res-size 1367 ;; 9. t if file's gid would change if file were deleted and
1353 ;; 8. File modes, as a string of ten letters or dashes as in ls -l. 1368 ;; recreated. Will be set in `tramp-convert-file-attributes'.
1354 res-filemodes 1369 t
1355 ;; 9. t if file's gid would change if file were deleted and 1370 ;; 10. Inode number.
1356 ;; recreated. Will be set in `tramp-convert-file-attributes'. 1371 res-inode
1357 t 1372 ;; 11. Device number. Will be replaced by a virtual device number.
1358 ;; 10. Inode number. 1373 -1
1359 res-inode 1374 ))))))
1360 ;; 11. Device number. Will be replaced by a virtual device number.
1361 -1
1362 )))))
1363 1375
1364(defun tramp-do-file-attributes-with-perl 1376(defun tramp-do-file-attributes-with-perl
1365 (vec localname &optional id-format) 1377 (vec localname &optional id-format)
diff --git a/test/automated/tramp-tests.el b/test/automated/tramp-tests.el
index c956f9cd008..915b30f5e08 100644
--- a/test/automated/tramp-tests.el
+++ b/test/automated/tramp-tests.el
@@ -1785,14 +1785,6 @@ Several special characters do not work properly there."
1785 (file-truename tramp-test-temporary-file-directory) nil 1785 (file-truename tramp-test-temporary-file-directory) nil
1786 (string-match "^HP-UX" (tramp-get-connection-property v "uname" "")))) 1786 (string-match "^HP-UX" (tramp-get-connection-property v "uname" ""))))
1787 1787
1788(defun tramp--test-darwin-p ()
1789 "Check, whether the remote host runs Mac OS X.
1790Several special characters do not work properly there."
1791 ;; We must refill the cache. `file-truename' does it.
1792 (with-parsed-tramp-file-name
1793 (file-truename tramp-test-temporary-file-directory) nil
1794 (string-match "^Darwin" (tramp-get-connection-property v "uname" ""))))
1795
1796(defun tramp--test-check-files (&rest files) 1788(defun tramp--test-check-files (&rest files)
1797 "Run a simple but comprehensive test over every file in FILES." 1789 "Run a simple but comprehensive test over every file in FILES."
1798 ;; We must use `file-truename' for the temporary directory, because 1790 ;; We must use `file-truename' for the temporary directory, because
@@ -2046,7 +2038,7 @@ Use the `ls' command."
2046 (file-name-coding-system 'utf-8)) 2038 (file-name-coding-system 'utf-8))
2047 (tramp--test-check-files 2039 (tramp--test-check-files
2048 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ") 2040 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
2049 (unless (or (tramp--test-hpux-p) (tramp--test-darwin-p)) 2041 (unless (tramp--test-hpux-p)
2050 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت") 2042 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
2051 "银河系漫游指南系列" 2043 "银河系漫游指南系列"
2052 "Автостопом по гала́ктике"))) 2044 "Автостопом по гала́ктике")))