]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-adb.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / net / tramp-adb.el
index 7c509e1d098d0f71ab5e35a40f67386f8574bc69..5940b713958a5d5585d09e988e5e9fd5ec94afc2 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tramp-adb.el --- Functions for calling Android Debug Bridge from Tramp
 
-;; Copyright (C) 2011-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
 
 ;; Author: Jürgen Hötzel <juergen@archlinux.org>
 ;; Keywords: comm, processes
@@ -35,9 +35,6 @@
 
 (require 'tramp)
 
-;; Pacify byte-compiler.
-(defvar directory-sep-char)
-
 ;;;###tramp-autoload
 (defcustom tramp-adb-program "adb"
   "Name of the Android Debug Bridge program."
@@ -59,7 +56,7 @@ It is used for TCP/IP devices."
 
 ;;;###tramp-autoload
 (defcustom tramp-adb-prompt
-  "^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
+  "^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]\e;[]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
   "Regexp used as prompt in almquist shell."
   :type 'string
   :version "24.4"
@@ -108,7 +105,6 @@ It is used for TCP/IP devices."
     (directory-files . tramp-handle-directory-files)
     (directory-files-and-attributes
      . tramp-adb-handle-directory-files-and-attributes)
-    (dired-call-process . ignore)
     (dired-compress-file . ignore)
     (dired-uncache . tramp-handle-dired-uncache)
     (expand-file-name . tramp-adb-handle-expand-file-name)
@@ -116,11 +112,11 @@ It is used for TCP/IP devices."
     (file-acl . ignore)
     (file-attributes . tramp-adb-handle-file-attributes)
     (file-directory-p . tramp-adb-handle-file-directory-p)
-    ;; `file-equal-p' performed by default handler.
+    (file-equal-p . tramp-handle-file-equal-p)
     ;; FIXME: This is too sloppy.
     (file-executable-p . tramp-handle-file-exists-p)
     (file-exists-p . tramp-handle-file-exists-p)
-    ;; `file-in-directory-p' performed by default handler.
+    (file-in-directory-p . tramp-handle-file-in-directory-p)
     (file-local-copy . tramp-adb-handle-file-local-copy)
     (file-modes . tramp-handle-file-modes)
     (file-name-all-completions . tramp-adb-handle-file-name-all-completions)
@@ -132,6 +128,7 @@ It is used for TCP/IP devices."
     (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
     (file-notify-add-watch . tramp-handle-file-notify-add-watch)
     (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
+    (file-notify-valid-p . tramp-handle-file-notify-valid-p)
     (file-ownership-preserved-p . ignore)
     (file-readable-p . tramp-handle-file-exists-p)
     (file-regular-p . tramp-handle-file-regular-p)
@@ -160,7 +157,7 @@ It is used for TCP/IP devices."
     (shell-command . tramp-adb-handle-shell-command)
     (start-file-process . tramp-adb-handle-start-file-process)
     (substitute-in-file-name . tramp-handle-substitute-in-file-name)
-    (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
+    (unhandled-file-name-directory . ignore)
     (vc-registered . ignore)
     (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
     (write-region . tramp-adb-handle-write-region))
@@ -197,7 +194,7 @@ pass to the OPERATION."
                       tramp-current-host nil nil))
            result)
        (tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " "))
-       (tramp-compat-set-process-query-on-exit-flag p nil)
+       (set-process-query-on-exit-flag p nil)
        (while (eq 'run (process-status p))
          (accept-process-output p 0.1))
        (accept-process-output p 0.1)
@@ -231,12 +228,9 @@ pass to the OPERATION."
       (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
        (setq localname (concat "/" localname)))
       ;; Do normal `expand-file-name' (this does "/./" and "/../").
-      ;; We bind `directory-sep-char' here for XEmacs on Windows,
-      ;; which would otherwise use backslash.  `default-directory' is
-      ;; bound, because on Windows there would be problems with UNC
-      ;; shares or Cygwin mounts.
-      (let ((directory-sep-char ?/)
-           (default-directory (tramp-compat-temporary-file-directory)))
+      ;; `default-directory' is bound, because on Windows there would
+      ;; be problems with UNC shares or Cygwin mounts.
+      (let ((default-directory (tramp-compat-temporary-file-directory)))
        (tramp-make-tramp-file-name
         method user host
         (tramp-drop-volume-letter
@@ -259,8 +253,7 @@ pass to the OPERATION."
       (with-tramp-file-property v localname "file-truename"
        (let ((result nil))                     ; result steps in reverse order
          (tramp-message v 4 "Finding true name for `%s'" filename)
-         (let* ((directory-sep-char ?/)
-                (steps (tramp-compat-split-string localname "/"))
+         (let* ((steps (split-string localname "/" 'omit))
                 (localnamedir (tramp-run-real-handler
                                'file-name-as-directory (list localname)))
                 (is-dir (string= localname localnamedir))
@@ -310,8 +303,7 @@ pass to the OPERATION."
                          "Symlink target `%s' on wrong host" symlink-target))
                       (setq symlink-target localname))
                     (setq steps
-                          (append (tramp-compat-split-string
-                                   symlink-target "/")
+                          (append (split-string symlink-target "/" 'omit)
                                   steps)))
                    (t
                     ;; It's a file.
@@ -394,41 +386,42 @@ pass to the OPERATION."
   "Like `directory-files-and-attributes' for Tramp files."
   (when (file-directory-p directory)
     (with-parsed-tramp-file-name (expand-file-name directory) nil
-      (with-tramp-file-property
-         v localname (format "directory-files-attributes-%s-%s-%s-%s"
-                             full match id-format nosort)
-       (with-current-buffer (tramp-get-buffer v)
-         (when (tramp-adb-send-command-and-check
-                v (format "%s -a -l %s"
-                          (tramp-adb-get-ls-command v)
-                          (tramp-shell-quote-argument localname)))
-           ;; We insert also filename/. and filename/.., because "ls" doesn't.
-           (narrow-to-region (point) (point))
-           (tramp-adb-send-command
-            v (format "%s -d -a -l %s %s"
-                      (tramp-adb-get-ls-command v)
-                      (tramp-shell-quote-argument
-                       (concat (file-name-as-directory localname) "."))
-                      (tramp-shell-quote-argument
-                       (concat (file-name-as-directory localname) ".."))))
-           (widen))
-         (tramp-adb-sh-fix-ls-output)
-         (let ((result (tramp-do-parse-file-attributes-with-ls
-                        v (or id-format 'integer))))
-           (when full
-             (setq result
-                   (mapcar
-                    (lambda (x)
-                      (cons (expand-file-name (car x) directory) (cdr x)))
-                    result)))
-           (unless nosort
-             (setq result
-                   (sort result (lambda (x y) (string< (car x) (car y))))))
-           (delq nil
-                 (mapcar (lambda (x)
-                           (if (or (not match) (string-match match (car x)))
-                               x))
-                         result))))))))
+      (copy-tree
+       (with-tramp-file-property
+          v localname (format "directory-files-and-attributes-%s-%s-%s-%s"
+                              full match id-format nosort)
+        (with-current-buffer (tramp-get-buffer v)
+          (when (tramp-adb-send-command-and-check
+                 v (format "%s -a -l %s"
+                           (tramp-adb-get-ls-command v)
+                           (tramp-shell-quote-argument localname)))
+            ;; We insert also filename/. and filename/.., because "ls" doesn't.
+            (narrow-to-region (point) (point))
+            (tramp-adb-send-command
+             v (format "%s -d -a -l %s %s"
+                       (tramp-adb-get-ls-command v)
+                       (tramp-shell-quote-argument
+                        (concat (file-name-as-directory localname) "."))
+                       (tramp-shell-quote-argument
+                        (concat (file-name-as-directory localname) ".."))))
+            (widen))
+          (tramp-adb-sh-fix-ls-output)
+          (let ((result (tramp-do-parse-file-attributes-with-ls
+                         v (or id-format 'integer))))
+            (when full
+              (setq result
+                    (mapcar
+                     (lambda (x)
+                       (cons (expand-file-name (car x) directory) (cdr x)))
+                     result)))
+            (unless nosort
+              (setq result
+                    (sort result (lambda (x y) (string< (car x) (car y))))))
+            (delq nil
+                  (mapcar (lambda (x)
+                            (if (or (not match) (string-match match (car x)))
+                                x))
+                          result)))))))))
 
 (defun tramp-adb-get-ls-command (vec)
   (with-tramp-connection-property vec "ls"
@@ -447,9 +440,8 @@ Convert (\"-al\") to (\"-a\" \"-l\").  Remove arguments like \"--dired\"."
   (split-string
    (apply 'concat
          (mapcar (lambda (s)
-                   (tramp-compat-replace-regexp-in-string
-                    "\\(.\\)"  " -\\1"
-                    (tramp-compat-replace-regexp-in-string "^-" "" s)))
+                   (replace-regexp-in-string
+                    "\\(.\\)"  " -\\1" (replace-regexp-in-string "^-" "" s)))
                  ;; FIXME: Warning about removed switches (long and non-dash).
                  (delq nil
                        (mapcar
@@ -497,12 +489,11 @@ Emacs dired can't find files."
 
 (defun tramp-adb-ls-output-name-less-p (a b)
   "Sort \"ls\" output by name, ascending."
-  (let (posa posb)
-    (string-match directory-listing-before-filename-regexp a)
-    (setq posa (match-end 0))
-    (string-match directory-listing-before-filename-regexp b)
-    (setq posb (match-end 0))
-    (string-lessp (substring a posa) (substring b posb))))
+  (if (string-match directory-listing-before-filename-regexp a)
+      (let ((posa (match-end 0)))
+       (if (string-match directory-listing-before-filename-regexp b)
+           (let ((posb (match-end 0)))
+             (string-lessp (substring a posa) (substring b posb)))))))
 
 (defun tramp-adb-handle-make-directory (dir &optional parents)
   "Like `make-directory' for Tramp files."
@@ -575,14 +566,15 @@ Emacs dired can't find files."
     (let ((tmpfile (tramp-compat-make-temp-file filename)))
       (with-tramp-progress-reporter
          v 3 (format "Fetching %s to tmp file %s" filename tmpfile)
-       (when (tramp-adb-execute-adb-command v "pull" localname tmpfile)
-         (delete-file tmpfile)
+       ;; "adb pull ..." does not always return an error code.
+       (when (or (tramp-adb-execute-adb-command v "pull" localname tmpfile)
+                 (not (file-exists-p tmpfile)))
+         (ignore-errors (delete-file tmpfile))
          (tramp-error
           v 'file-error "Cannot make local copy of file `%s'" filename))
        (set-file-modes
         tmpfile
-        (logior (or (file-modes filename) 0)
-                (tramp-compat-octal-to-decimal "0400"))))
+        (logior (or (file-modes filename) 0) (string-to-number "0400" 8))))
       tmpfile)))
 
 (defun tramp-adb-handle-file-writable-p (filename)
@@ -627,13 +619,13 @@ But handle the case, if the \"test\" command is not available."
        (copy-file filename tmpfile 'ok)
        (set-file-modes
         tmpfile
-        (logior (or (file-modes tmpfile) 0)
-                (tramp-compat-octal-to-decimal "0600"))))
+        (logior (or (file-modes tmpfile) 0) (string-to-number "0600" 8))))
       (tramp-run-real-handler
        'write-region
        (list start end tmpfile append 'no-message lockname confirm))
       (with-tramp-progress-reporter
-         v 3 (format "Moving tmp file `%s' to `%s'" tmpfile filename)
+        v 3 (format-message
+             "Moving tmp file `%s' to `%s'" tmpfile filename)
        (unwind-protect
            (when (tramp-adb-execute-adb-command v "push" tmpfile localname)
              (tramp-error v 'file-error "Cannot write: `%s'" filename))
@@ -650,13 +642,14 @@ But handle the case, if the \"test\" command is not available."
 (defun tramp-adb-handle-set-file-modes (filename mode)
   "Like `set-file-modes' for Tramp files."
   (with-parsed-tramp-file-name filename nil
+    (tramp-flush-file-property v (file-name-directory localname))
     (tramp-flush-file-property v localname)
-    (tramp-adb-send-command-and-check
-     v (format "chmod %s %s" (tramp-compat-decimal-to-octal mode) localname))))
+    (tramp-adb-send-command-and-check v (format "chmod %o %s" mode localname))))
 
 (defun tramp-adb-handle-set-file-times (filename &optional time)
   "Like `set-file-times' for Tramp files."
   (with-parsed-tramp-file-name filename nil
+    (tramp-flush-file-property v (file-name-directory localname))
     (tramp-flush-file-property v localname)
     (let ((time (if (or (null time) (equal time '(0 0)))
                    (current-time)
@@ -729,10 +722,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
        (if (and t1 t2
                 (tramp-equal-remote filename newname)
                 (not (file-directory-p filename)))
-           (let ((l1 (tramp-file-name-handler
-                      'file-remote-p filename 'localname))
-                 (l2 (tramp-file-name-handler
-                      'file-remote-p newname 'localname)))
+           (let ((l1 (file-remote-p filename 'localname))
+                 (l2 (file-remote-p newname 'localname)))
              (when (and (not ok-if-already-exists)
                         (file-exists-p newname))
                (tramp-error v 'file-already-exists newname))
@@ -748,7 +739,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
               "Error renaming %s to %s" filename newname))
 
          ;; Rename by copy.
-         (copy-file filename newname ok-if-already-exists t t)
+         (copy-file
+          filename newname ok-if-already-exists 'keep-time 'preserve-uid-gid)
          (delete-file filename))))))
 
 (defun tramp-adb-handle-process-file
@@ -849,12 +841,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
       ;; because the remote process could have changed them.
       (when tmpinput (delete-file tmpinput))
 
-      ;; `process-file-side-effects' has been introduced with GNU
-      ;; Emacs 23.2.  If set to nil, no remote file will be changed
-      ;; by `program'.  If it doesn't exist, we assume its default
-      ;; value t.
-      (unless (and (boundp 'process-file-side-effects)
-                  (not (symbol-value 'process-file-side-effects)))
+      (unless process-file-side-effects
         (tramp-flush-directory-property v ""))
 
       ;; Return exit status.
@@ -934,9 +921,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
                                     (current-buffer))))
          ;; There's some output, display it.
          (when (with-current-buffer output-buffer (> (point-max) (point-min)))
-           (if (functionp 'display-message-or-buffer)
-               (tramp-compat-funcall 'display-message-or-buffer output-buffer)
-             (pop-to-buffer output-buffer))))))))
+           (display-message-or-buffer output-buffer)))))))
 
 ;; We use BUFFER also as connection buffer during setup.  Because of
 ;; this, its original contents must be saved, and restored once
@@ -1001,7 +986,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
                    ;; process.  We ignore errors, because the process
                    ;; could have finished already.
                    (ignore-errors
-                     (tramp-compat-set-process-query-on-exit-flag p t)
+                     (set-process-query-on-exit-flag p t)
                      (set-marker (process-mark p) (point)))
                    ;; Return process.
                    p))))
@@ -1198,7 +1183,7 @@ connection if a previous connection has died for some reason."
            (unless (eq 'run (process-status p))
              (tramp-error  vec 'file-error "Terminated!"))
            (tramp-set-connection-property p "vector" vec)
-           (tramp-compat-set-process-query-on-exit-flag p nil)
+           (set-process-query-on-exit-flag p nil)
 
            ;; Check whether the properties have been changed.  If
            ;; yes, this is a strong indication that we must expire all
@@ -1243,7 +1228,10 @@ connection if a previous connection has died for some reason."
                ;; Read the expression.
                (goto-char (point-min))
                (read (current-buffer)))
-             ":" 'omit-nulls))))))))
+             ":" 'omit))
+
+           ;; Mark it as connected.
+           (tramp-set-connection-property p "connected" t)))))))
 
 (add-hook 'tramp-unload-hook
          (lambda ()