aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2013-01-05 14:41:57 +0100
committerMichael Albinus2013-01-05 14:41:57 +0100
commit838cf2981c3ce4fe6e1b7aa6c90c947c6d4bf027 (patch)
treeab6dac07f24a8e2aa515df94ea8b38edbe6bcffe
parent1bd71e9fe16541bc48868a00ff372018961380b0 (diff)
downloademacs-838cf2981c3ce4fe6e1b7aa6c90c947c6d4bf027.tar.gz
emacs-838cf2981c3ce4fe6e1b7aa6c90c947c6d4bf027.zip
* net/tramp-adb.el (tramp-adb-handle-file-attributes): More robust
parsing of ls output using regular expression (handle filenames with spaces). Use virtual device number. (tramp-do-parse-file-attributes-with-ls): New defun (Code cleanup).
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/net/tramp-adb.el99
2 files changed, 83 insertions, 24 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5b54d34743c..5ec36240b9e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12013-01-05 Jürgen Hötzel <juergen@archlinux.org>
2
3 * net/tramp-adb.el (tramp-adb-handle-file-attributes): More robust
4 parsing of ls output using regular expression (handle filenames
5 with spaces). Use virtual device number.
6 (tramp-do-parse-file-attributes-with-ls): New defun (Code
7 cleanup).
8
12013-01-04 Daiki Ueno <ueno@gnu.org> 92013-01-04 Daiki Ueno <ueno@gnu.org>
2 10
3 * epg.el: Silence byte-compiler warnings. 11 * epg.el: Silence byte-compiler warnings.
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index b5f99ffc93c..b555746620a 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -56,6 +56,15 @@
56(defconst tramp-adb-ls-date-regexp 56(defconst tramp-adb-ls-date-regexp
57 "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]") 57 "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]")
58 58
59(defconst tramp-adb-ls-toolbox-regexp
60 (concat
61 "^[[:space:]]*\\([-[:alpha:]]+\\)" ; \1 permissions
62 "[[:space:]]*\\([^[:space:]]+\\)" ; \2 username
63 "[[:space:]]+\\([^[:space:]]+\\)" ; \3 group
64 "[[:space:]]+\\([[:digit:]]\\)" ; \4 size
65 "[[:space:]]+\\([-[:digit:]]+[[:space:]][:[:digit:]]+\\)" ; \5 date
66 "[[:space:]]+\\(.*\\)$")) ; \6 filename
67
59;;;###tramp-autoload 68;;;###tramp-autoload
60(add-to-list 'tramp-methods `(,tramp-adb-method)) 69(add-to-list 'tramp-methods `(,tramp-adb-method))
61 70
@@ -95,6 +104,9 @@
95 (expand-file-name . tramp-adb-handle-expand-file-name) 104 (expand-file-name . tramp-adb-handle-expand-file-name)
96 (find-backup-file-name . tramp-handle-find-backup-file-name) 105 (find-backup-file-name . tramp-handle-find-backup-file-name)
97 (directory-files . tramp-handle-directory-files) 106 (directory-files . tramp-handle-directory-files)
107 (directory-files-and-attributes
108 . tramp-adb-handle-directory-files-and-attributes)
109 (file-name-all-completions . tramp-sh-handle-file-name-all-completions)
98 (make-directory . tramp-adb-handle-make-directory) 110 (make-directory . tramp-adb-handle-make-directory)
99 (delete-directory . tramp-adb-handle-delete-directory) 111 (delete-directory . tramp-adb-handle-delete-directory)
100 (delete-file . tramp-adb-handle-delete-file) 112 (delete-file . tramp-adb-handle-delete-file)
@@ -280,30 +292,69 @@ pass to the OPERATION."
280 (tramp-shell-quote-argument localname)) "") 292 (tramp-shell-quote-argument localname)) "")
281 (with-current-buffer (tramp-get-buffer v) 293 (with-current-buffer (tramp-get-buffer v)
282 (tramp-adb-sh-fix-ls-output) 294 (tramp-adb-sh-fix-ls-output)
283 (let* ((columns (split-string (buffer-string))) 295 (cdar (tramp-do-parse-file-attributes-with-ls v id-format)))))))
284 (mod-string (nth 0 columns)) 296
285 (is-dir (eq ?d (aref mod-string 0))) 297(defun tramp-do-parse-file-attributes-with-ls (vec &optional id-format)
286 (is-symlink (eq ?l (aref mod-string 0))) 298 "Parse `file-attributes' for Tramp files using the ls(1) command."
287 (symlink-target 299 (with-current-buffer (tramp-get-buffer vec)
288 (and is-symlink 300 (goto-char (point-min))
289 (cadr (split-string (buffer-string) "\\( -> \\|\n\\)")))) 301 (let ((file-properties nil))
290 (uid (nth 1 columns)) 302 (while (re-search-forward tramp-adb-ls-toolbox-regexp nil t)
291 (gid (nth 2 columns)) 303 (let* ((mod-string (match-string 1))
292 (date (format "%s %s" (nth 4 columns) (nth 5 columns))) 304 (is-dir (eq ?d (aref mod-string 0)))
293 (size (string-to-number (nth 3 columns)))) 305 (is-symlink (eq ?l (aref mod-string 0)))
294 (list 306 (uid (match-string 2))
295 (or is-dir symlink-target) 307 (gid (match-string 3))
296 1 ;link-count 308 (size (string-to-number (match-string 4)))
297 ;; no way to handle numeric ids in Androids ash 309 (date (match-string 5))
298 (if (eq id-format 'integer) 0 uid) 310 (name (match-string 6))
299 (if (eq id-format 'integer) 0 gid) 311 (symlink-target
300 '(0 0) ; atime 312 (and is-symlink
301 (date-to-time date) ; mtime 313 (cadr (split-string name "\\( -> \\|\n\\)")))))
302 '(0 0) ; ctime 314 (push (list
303 size 315 name
304 mod-string 316 (or is-dir symlink-target)
305 ;; fake 317 1 ;link-count
306 t 1 1))))))) 318 ;; no way to handle numeric ids in Androids ash
319 (if (eq id-format 'integer) 0 uid)
320 (if (eq id-format 'integer) 0 gid)
321 '(0 0) ; atime
322 (date-to-time date) ; mtime
323 '(0 0) ; ctime
324 size
325 mod-string
326 ;; fake
327 t 1
328 (tramp-get-device v))
329 file-properties)))
330 file-properties)))
331
332(defun tramp-adb-handle-directory-files-and-attributes
333 (directory &optional full match nosort id-format)
334 "Like `directory-files-and-attributes' for Tramp files."
335 (when (file-directory-p directory)
336 (with-parsed-tramp-file-name (expand-file-name directory) nil
337 (with-tramp-file-property
338 v localname (format "directory-files-attributes-%s-%s-%s-s"
339 full match id-format nosort)
340 (tramp-adb-barf-unless-okay
341 v (format "%s -a -l %s"
342 (tramp-adb-get-ls-command v)
343 (tramp-shell-quote-argument localname)) "")
344 (with-current-buffer (tramp-get-buffer v)
345 (tramp-adb-sh-fix-ls-output)
346 (let ((result (tramp-do-parse-file-attributes-with-ls v (or id-format 'integer))))
347 (when full
348 (setq result (mapcar
349 (lambda (x) (cons (expand-file-name (car x) directory) (cdr x)))
350 result)))
351 (unless nosort
352 (setq result (sort result (lambda (x y) (string< (car x) (car y))))))
353 (delq nil
354 (mapcar (lambda (x)
355 (if (or (not match) (string-match match (car x)))
356 x))
357 result))))))))
307 358
308(defun tramp-adb-get-ls-command (vec) 359(defun tramp-adb-get-ls-command (vec)
309 (with-tramp-connection-property vec "ls" 360 (with-tramp-connection-property vec "ls"