diff options
Diffstat (limited to 'lisp/net')
| -rw-r--r-- | lisp/net/ange-ftp.el | 14 | ||||
| -rw-r--r-- | lisp/net/browse-url.el | 5 | ||||
| -rw-r--r-- | lisp/net/dbus.el | 6 | ||||
| -rw-r--r-- | lisp/net/eudcb-bbdb.el | 24 | ||||
| -rw-r--r-- | lisp/net/goto-addr.el | 2 | ||||
| -rw-r--r-- | lisp/net/ldap.el | 1 | ||||
| -rw-r--r-- | lisp/net/newst-backend.el | 2 | ||||
| -rw-r--r-- | lisp/net/newst-treeview.el | 4 | ||||
| -rw-r--r-- | lisp/net/newsticker.el | 2 | ||||
| -rw-r--r-- | lisp/net/quickurl.el | 2 | ||||
| -rw-r--r-- | lisp/net/rcirc.el | 59 | ||||
| -rw-r--r-- | lisp/net/snmp-mode.el | 4 | ||||
| -rw-r--r-- | lisp/net/tls.el | 16 | ||||
| -rw-r--r-- | lisp/net/tramp-adb.el | 988 | ||||
| -rw-r--r-- | lisp/net/tramp-cache.el | 39 | ||||
| -rw-r--r-- | lisp/net/tramp-cmds.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-compat.el | 20 | ||||
| -rw-r--r-- | lisp/net/tramp-ftp.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-gvfs.el | 18 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 166 | ||||
| -rw-r--r-- | lisp/net/tramp-smb.el | 37 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 101 | ||||
| -rw-r--r-- | lisp/net/trampver.el | 4 | ||||
| -rw-r--r-- | lisp/net/webjump.el | 2 |
24 files changed, 1274 insertions, 246 deletions
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el index 1501fa41baa..265a855b842 100644 --- a/lisp/net/ange-ftp.el +++ b/lisp/net/ange-ftp.el @@ -79,7 +79,7 @@ ;; that this change will take effect for the current GNU Emacs session only. ;; See below for a discussion of non-UNIX hosts. If a large number of ;; machines with similar hostnames have this problem then it is easier to set -;; the value of ange-ftp-dumb-unix-host-regexp in your .emacs file. ange-ftp +;; the value of ange-ftp-dumb-unix-host-regexp in your init file. ange-ftp ;; is unable to automatically recognize dumb unix hosts. ;; File name completion: @@ -275,10 +275,10 @@ ;; VMS support: ;; -;; Ange-ftp has full support for VMS hosts. It -;; should be able to automatically recognize any VMS machine. However, if it -;; fails to do this, you can use the command ange-ftp-add-vms-host. As well, -;; you can set the variable ange-ftp-vms-host-regexp in your .emacs file. We +;; Ange-ftp has full support for VMS hosts. It should be able to +;; automatically recognize any VMS machine. However, if it fails to do +;; this, you can use the command ange-ftp-add-vms-host. Also, you can +;; set the variable ange-ftp-vms-host-regexp in your init file. We ;; would be grateful if you would report any failures to automatically ;; recognize a VMS host as a bug. ;; @@ -332,7 +332,7 @@ ;; the Michigan terminal system. It should be able to automatically ;; recognize any MTS machine. However, if it fails to do this, you can use ;; the command ange-ftp-add-mts-host. As well, you can set the variable -;; ange-ftp-mts-host-regexp in your .emacs file. We would be grateful if you +;; ange-ftp-mts-host-regexp in your init file. We would be grateful if you ;; would report any failures to automatically recognize a MTS host as a bug. ;; ;; Filename syntax: @@ -358,7 +358,7 @@ ;; CMS. It should be able to automatically recognize any CMS machine. ;; However, if it fails to do this, you can use the command ;; ange-ftp-add-cms-host. As well, you can set the variable -;; ange-ftp-cms-host-regexp in your .emacs file. We would be grateful if you +;; ange-ftp-cms-host-regexp in your init file. We would be grateful if you ;; would report any failures to automatically recognize a CMS host as a bug. ;; ;; Filename syntax: diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 20d71215926..c1c83d2245e 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -122,8 +122,7 @@ ;; the buffer, use: ;; M-x browse-url -;; To display a URL by shift-clicking on it, put this in your ~/.emacs -;; file: +;; To display a URL by shift-clicking on it, put this in your init file: ;; (global-set-key [S-mouse-2] 'browse-url-at-mouse) ;; (Note that using Shift-mouse-1 is not desirable because ;; that event has a standard meaning in Emacs.) @@ -743,7 +742,7 @@ narrowed." (and buffer (set-buffer buffer)) (let ((file-name ;; Ignore real name if restricted - (and (= (- (point-max) (point-min)) (buffer-size)) + (and (not (buffer-narrowed-p)) (or buffer-file-name (and (boundp 'dired-directory) dired-directory))))) (or file-name diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index 772a0a9c626..c95e901c39d 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el @@ -152,7 +152,9 @@ Otherwise, return result of last form in BODY, or all other errors." (dbus-error (when dbus-debug (signal (car err) (cdr err)))))) (font-lock-add-keywords 'emacs-lisp-mode '("\\<dbus-ignore-errors\\>")) -(defvar dbus-event-error-hooks nil +(define-obsolete-variable-alias 'dbus-event-error-hooks + 'dbus-event-error-functions "24.3") +(defvar dbus-event-error-functions nil "Functions to be called when a D-Bus error happens in the event handler. Every function must accept two arguments, the event and the error variable caught in `condition-case' by `dbus-error'.") @@ -947,7 +949,7 @@ If the HANDLER returns a `dbus-error', it is propagated as return message." (dbus-method-error-internal (nth 1 event) (nth 4 event) (nth 3 event) (cadr err)))) ;; Propagate D-Bus error messages. - (run-hook-with-args 'dbus-event-error-hooks event err) + (run-hook-with-args 'dbus-event-error-functions event err) (when (or dbus-debug (= dbus-message-type-error (nth 2 event))) (signal (car err) (cdr err)))))) diff --git a/lisp/net/eudcb-bbdb.el b/lisp/net/eudcb-bbdb.el index 9d160fe319d..42b618815f5 100644 --- a/lisp/net/eudcb-bbdb.el +++ b/lisp/net/eudcb-bbdb.el @@ -166,18 +166,18 @@ The record is filtered according to `eudc-bbdb-current-return-attributes'" (symbol-name attr))) 'record)))) (t - (setq val "Unknown BBDB attribute"))) - (if val - (cond - ((memq attr '(phones addresses)) - (setq eudc-rec (append val eudc-rec))) - ((and (listp val) - (= 1 (length val))) - (setq eudc-rec (cons (cons attr (car val)) eudc-rec))) - ((> (length val) 0) - (setq eudc-rec (cons (cons attr val) eudc-rec))) - (t - (error "Unexpected attribute value"))))) + (error "Unknown BBDB attribute"))) + (cond + ((or (not val) (equal val ""))) ; do nothing + ((memq attr '(phones addresses)) + (setq eudc-rec (append val eudc-rec))) + ((and (listp val) + (= 1 (length val))) + (setq eudc-rec (cons (cons attr (car val)) eudc-rec))) + ((> (length val) 0) + (setq eudc-rec (cons (cons attr val) eudc-rec))) + (t + (error "Unexpected attribute value")))) (nreverse eudc-rec))) diff --git a/lisp/net/goto-addr.el b/lisp/net/goto-addr.el index 6a9d80f9672..f9e31788527 100644 --- a/lisp/net/goto-addr.el +++ b/lisp/net/goto-addr.el @@ -33,7 +33,7 @@ ;; INSTALLATION ;; ;; To use goto-address in a particular mode (for example, while -;; reading mail in mh-e), add something like this in your .emacs file: +;; reading mail in mh-e), add this to your init file: ;; ;; (add-hook 'mh-show-mode-hook 'goto-address) ;; diff --git a/lisp/net/ldap.el b/lisp/net/ldap.el index eb696798b6f..6ef713de93d 100644 --- a/lisp/net/ldap.el +++ b/lisp/net/ldap.el @@ -604,6 +604,7 @@ an alist of attribute/value pairs." ;; Skip error message when retrieving attribute list (if (looking-at "Size limit exceeded") (forward-line 1)) + (if (looking-at "version:") (forward-line 1)) ;bug#12724. (while (progn (skip-chars-forward " \t\n") (not (eobp))) diff --git a/lisp/net/newst-backend.el b/lisp/net/newst-backend.el index c78249ced0f..bc6fd38f713 100644 --- a/lisp/net/newst-backend.el +++ b/lisp/net/newst-backend.el @@ -421,7 +421,7 @@ headline after it has been retrieved for the first time." "Name of the newsticker cache file." :type 'string :group 'newsticker-miscellaneous) -(make-obsolete 'newsticker-cache-filename 'newsticker-dir "23.1") +(make-obsolete-variable 'newsticker-cache-filename 'newsticker-dir "23.1") (defcustom newsticker-dir (locate-user-emacs-file "newsticker/" ".newsticker/") diff --git a/lisp/net/newst-treeview.el b/lisp/net/newst-treeview.el index b44f1f9c86d..0bc7d6ad6ea 100644 --- a/lisp/net/newst-treeview.el +++ b/lisp/net/newst-treeview.el @@ -128,7 +128,7 @@ Example: (\"Topmost group\" \"feed1\" (\"subgroup1\" \"feed 2\") "Name of the newsticker groups settings file." :type 'string :group 'newsticker-treeview) -(make-obsolete 'newsticker-groups-filename 'newsticker-dir "23.1") +(make-obsolete-variable 'newsticker-groups-filename 'newsticker-dir "23.1") ;; ====================================================================== ;;; internal variables @@ -1722,7 +1722,7 @@ return a nested list." (defun newsticker-group-move-feed (name group-name &optional no-update) "Move feed NAME to group GROUP-NAME. -Update teeview afterwards unless NO-UPDATE is non-nil." +Update treeview afterwards unless NO-UPDATE is non-nil." (interactive (let ((completion-ignore-case t)) (list (completing-read "Feed Name: " diff --git a/lisp/net/newsticker.el b/lisp/net/newsticker.el index 5d673faf0db..91eca84ce53 100644 --- a/lisp/net/newsticker.el +++ b/lisp/net/newsticker.el @@ -87,7 +87,7 @@ ;; If you are using Newsticker as part of GNU Emacs there is no need to ;; perform any installation steps in order to use Newsticker. Otherwise ;; place Newsticker in a directory where Emacs can find it. Add the -;; following line to your Emacs startup file (`~/.emacs'). +;; following line to your init file: ;; (add-to-list 'load-path "/path/to/newsticker/") ;; (autoload 'newsticker-start "newsticker" "Emacs Newsticker" t) ;; (autoload 'newsticker-show-news "newsticker" "Emacs Newsticker" t) diff --git a/lisp/net/quickurl.el b/lisp/net/quickurl.el index f3b0e372de4..f7d41fcd97a 100644 --- a/lisp/net/quickurl.el +++ b/lisp/net/quickurl.el @@ -164,7 +164,7 @@ To make use of this do something like: (setq quickurl-postfix quickurl-reread-hook-postfix) -in your ~/.emacs (after loading/requiring quickurl).") +in your init file (after loading/requiring quickurl).") ;; Non-customize variables. diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el index dd345630b9b..16644b57549 100644 --- a/lisp/net/rcirc.el +++ b/lisp/net/rcirc.el @@ -300,7 +300,9 @@ See `rcirc-dim-nick' face." :type '(repeat string) :group 'rcirc) -(defcustom rcirc-print-hooks nil +(define-obsolete-variable-alias 'rcirc-print-hooks + 'rcirc-print-functions "24.3") +(defcustom rcirc-print-functions nil "Hook run after text is printed. Called with 5 arguments, PROCESS, SENDER, RESPONSE, TARGET and TEXT." :type 'hook @@ -404,7 +406,7 @@ will be killed." "The channel or user associated with this buffer.") (defvar rcirc-urls nil - "List of urls seen in the current buffer.") + "List of URLs seen in the current buffer and their start positions.") (put 'rcirc-urls 'permanent-local t) (defvar rcirc-timeout-seconds 600 @@ -647,7 +649,9 @@ is non-nil." "] " text))))) -(defvar rcirc-sentinel-hooks nil +(define-obsolete-variable-alias 'rcirc-sentinel-hooks + 'rcirc-sentinel-functions "24.3") +(defvar rcirc-sentinel-functions nil "Hook functions called when the process sentinel is called. Functions are called with PROCESS and SENTINEL arguments.") @@ -664,7 +668,7 @@ Functions are called with PROCESS and SENTINEL arguments.") sentinel (process-status process)) (not rcirc-target)) (rcirc-disconnect-buffer))) - (run-hook-with-args 'rcirc-sentinel-hooks process sentinel)))) + (run-hook-with-args 'rcirc-sentinel-functions process sentinel)))) (defun rcirc-disconnect-buffer (&optional buffer) (with-current-buffer (or buffer (current-buffer)) @@ -684,7 +688,9 @@ Functions are called with PROCESS and SENTINEL arguments.") (process-list)) ps)) -(defvar rcirc-receive-message-hooks nil +(define-obsolete-variable-alias 'rcirc-receive-message-hooks + 'rcirc-receive-message-functions "24.3") +(defvar rcirc-receive-message-functions nil "Hook functions run when a message is received from server. Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.") (defun rcirc-filter (process output) @@ -738,7 +744,7 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.") (if (not (fboundp handler)) (rcirc-handler-generic process cmd sender args text) (funcall handler process sender args text)) - (run-hook-with-args 'rcirc-receive-message-hooks + (run-hook-with-args 'rcirc-receive-message-functions process cmd sender args text))) (message "UNHANDLED: %s" text))) @@ -1625,7 +1631,7 @@ record activity." (rcirc-log process sender response target text)) (sit-for 0) ; displayed text before hook - (run-hook-with-args 'rcirc-print-hooks + (run-hook-with-args 'rcirc-print-functions process sender response target text))))) (defun rcirc-generate-log-filename (process target) @@ -1927,7 +1933,9 @@ With prefix ARG, go to the next low priority buffer with activity." (key-description (this-command-keys)) " for low priority activity.")))))))) -(defvar rcirc-activity-hooks nil +(define-obsolete-variable-alias 'rcirc-activity-hooks + 'rcirc-activity-functions "24.3") +(defvar rcirc-activity-functions nil "Hook to be run when there is channel activity. Functions are called with a single argument, the buffer with the @@ -1950,7 +1958,7 @@ activity. Only run if the buffer is not visible and (unless (and (equal rcirc-activity old-activity) (member type old-types)) (rcirc-update-activity-string))))) - (run-hook-with-args 'rcirc-activity-hooks buffer)) + (run-hook-with-args 'rcirc-activity-functions buffer)) (defun rcirc-clear-activity (buffer) "Clear the BUFFER activity." @@ -2384,12 +2392,25 @@ keywords when no KEYWORD is given." "\\)") "Regexp matching URLs. Set to nil to disable URL features in rcirc.") +;; cf cl-remove-if-not +(defun rcirc-condition-filter (condp lst) + "Remove all items not satisfying condition CONDP in list LST. +CONDP is a function that takes a list element as argument and returns +non-nil if that element should be included. Returns a new list." + (delq nil (mapcar (lambda (x) (and (funcall condp x) x)) lst))) + (defun rcirc-browse-url (&optional arg) - "Prompt for URL to browse based on URLs in buffer." + "Prompt for URL to browse based on URLs in buffer before point. + +If ARG is given, opens the URL in a new browser window." (interactive "P") - (let ((completions (mapcar (lambda (x) (cons x nil)) rcirc-urls)) - (initial-input (car rcirc-urls)) - (history (cdr rcirc-urls))) + (let* ((point (point)) + (filtered (rcirc-condition-filter + (lambda (x) (>= point (cdr x))) + rcirc-urls)) + (completions (mapcar (lambda (x) (car x)) filtered)) + (initial-input (caar filtered)) + (history (mapcar (lambda (x) (car x)) (cdr filtered)))) (browse-url (completing-read "rcirc browse-url: " completions nil nil initial-input 'history) arg))) @@ -2433,17 +2454,19 @@ keywords when no KEYWORD is given." (defun rcirc-markup-urls (sender response) (while (and rcirc-url-regexp ;; nil means disable URL catching (re-search-forward rcirc-url-regexp nil t)) - (let ((start (match-beginning 0)) - (end (match-end 0)) - (url (match-string-no-properties 0))) + (let* ((start (match-beginning 0)) + (end (match-end 0)) + (url (match-string-no-properties 0)) + (link-text (buffer-substring-no-properties start end))) (make-button start end 'face 'rcirc-url 'follow-link t 'rcirc-url url 'action (lambda (button) (browse-url (button-get button 'rcirc-url)))) - ;; record the url - (push url rcirc-urls)))) + ;; record the url if it is not already the latest stored url + (when (not (string= link-text (caar rcirc-urls))) + (push (cons link-text start) rcirc-urls))))) (defun rcirc-markup-keywords (sender response) (when (and (string= response "PRIVMSG") diff --git a/lisp/net/snmp-mode.el b/lisp/net/snmp-mode.el index c155d53b6d0..217f9dc8b30 100644 --- a/lisp/net/snmp-mode.el +++ b/lisp/net/snmp-mode.el @@ -175,9 +175,9 @@ This is used during Tempo template completion." (defvar snmp-font-lock-keywords-3 (append '(("\\([^\n]+\\)[ \t]+::=[ \t]+\\(SEQUENCE\\)[ \t]+{" - (1 font-lock-reference-face) (2 font-lock-keyword-face)) + (1 font-lock-constant-face) (2 font-lock-keyword-face)) ("::=[ \t]*{[ \t]*\\([a-z0-9].*[ \t]+\\)?\\([0-9]+\\)[ \t]*}" - (1 font-lock-reference-face nil t) (2 font-lock-variable-name-face))) + (1 font-lock-constant-face nil t) (2 font-lock-variable-name-face))) snmp-font-lock-keywords-2) "Gaudy SNMP MIB mode expression highlighting.") diff --git a/lisp/net/tls.el b/lisp/net/tls.el index 75d178e3225..116c7e9d84a 100644 --- a/lisp/net/tls.el +++ b/lisp/net/tls.el @@ -89,10 +89,14 @@ Also see `tls-success' for what the program should output after successful negotiation." :type '(choice + (const :tag "Default list of commands" + ("gnutls-cli --insecure -p %p %h" + "gnutls-cli --insecure -p %p %h --protocols ssl3" + "openssl s_client -connect %h:%p -no_ssl2 -ign_eof")) (list :tag "Choose commands" :value - ("gnutls-cli -p %p %h" - "gnutls-cli -p %p %h --protocols ssl3" + ("gnutls-cli --insecure -p %p %h" + "gnutls-cli --insecure -p %p %h --protocols ssl3" "openssl s_client -connect %h:%p -no_ssl2 -ign_eof") (set :inline t ;; FIXME: add brief `:tag "..."' descriptions. @@ -102,14 +106,10 @@ successful negotiation." (const "gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p %p %h --protocols ssl3") (const "openssl s_client -connect %h:%p -CAfile /etc/ssl/certs/ca-certificates.crt -no_ssl2 -ign_eof") ;; No trust check: - (const "gnutls-cli -p %p %h") - (const "gnutls-cli -p %p %h --protocols ssl3") + (const "gnutls-cli --insecure -p %p %h") + (const "gnutls-cli --insecure -p %p %h --protocols ssl3") (const "openssl s_client -connect %h:%p -no_ssl2 -ign_eof")) (repeat :inline t :tag "Other" (string))) - (const :tag "Default list of commands" - ("gnutls-cli -p %p %h" - "gnutls-cli -p %p %h --protocols ssl3" - "openssl s_client -connect %h:%p -no_ssl2 -ign_eof")) (list :tag "List of commands" (repeat :tag "Command" (string)))) :version "22.1" diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el new file mode 100644 index 00000000000..d34980fe22e --- /dev/null +++ b/lisp/net/tramp-adb.el @@ -0,0 +1,988 @@ +;;; tramp-adb.el --- Functions for calling Android Debug Bridge from Tramp + +;; Copyright (C) 2011-2012 Free Software Foundation, Inc. + +;; Author: Juergen Hoetzel <juergen@archlinux.org> +;; Keywords: comm, processes +;; Package: tramp + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; The Android Debug Bridge must be installed on your local machine. +;; Add the following form into your .emacs: +;; +;; (setq tramp-adb-sdk-dir "/path/to/android/sdk") +;; +;; Due to security it is not possible to access non-root devices. + +;;; Code: + +(require 'tramp) + +(defvar dired-move-to-filename-regexp) + +(defcustom tramp-adb-sdk-dir "~/Android/sdk" + "Set to the directory containing the Android SDK." + :type 'string + :version "24.4" + :group 'tramp) + +;;;###tramp-autoload +(defconst tramp-adb-method "adb" + "*When this method name is used, forward all calls to Android Debug Bridge.") + +(defcustom tramp-adb-prompt "^\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]" + "Regexp used as prompt in almquist shell." + :type 'string + :version "24.4" + :group 'tramp) + +(defconst tramp-adb-ls-date-regexp "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]") + +;;;###tramp-autoload +(add-to-list 'tramp-methods `(,tramp-adb-method)) + +;;;###tramp-autoload +(eval-after-load 'tramp + '(tramp-set-completion-function + tramp-adb-method '((tramp-adb-parse-device-names "")))) + +;;;###tramp-autoload +(add-to-list 'tramp-foreign-file-name-handler-alist + (cons 'tramp-adb-file-name-p 'tramp-adb-file-name-handler)) + +(defconst tramp-adb-file-name-handler-alist + '((directory-file-name . tramp-handle-directory-file-name) + (dired-uncache . tramp-handle-dired-uncache) + (file-name-as-directory . tramp-handle-file-name-as-directory) + (file-name-completion . tramp-handle-file-name-completion) + (file-name-all-completions . tramp-adb-handle-file-name-all-completions) + (file-attributes . tramp-adb-handle-file-attributes) + (file-name-directory . tramp-handle-file-name-directory) + (file-name-nondirectory . tramp-handle-file-name-nondirectory) + (file-truename . tramp-adb-handle-file-truename) + (file-newer-than-file-p . tramp-handle-file-newer-than-file-p) + (file-name-as-directory . tramp-handle-file-name-as-directory) + (file-regular-p . tramp-handle-file-regular-p) + (file-remote-p . tramp-handle-file-remote-p) + (file-directory-p . tramp-adb-handle-file-directory-p) + (file-symlink-p . tramp-handle-file-symlink-p) + ;; FIXME: This is too sloppy. + (file-executable-p . file-exists-p) + (file-exists-p . tramp-adb-handle-file-exists-p) + (file-readable-p . tramp-handle-file-exists-p) + (file-writable-p . tramp-adb-handle-file-writable-p) + (file-local-copy . tramp-adb-handle-file-local-copy) + (file-modes . tramp-handle-file-modes) + (expand-file-name . tramp-adb-handle-expand-file-name) + (find-backup-file-name . tramp-handle-find-backup-file-name) + (directory-files . tramp-handle-directory-files) + (make-directory . tramp-adb-handle-make-directory) + (delete-directory . tramp-adb-handle-delete-directory) + (delete-file . tramp-adb-handle-delete-file) + (load . tramp-handle-load) + (insert-directory . tramp-adb-handle-insert-directory) + (insert-file-contents . tramp-handle-insert-file-contents) + (substitute-in-file-name . tramp-handle-substitute-in-file-name) + (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory) + (vc-registered . ignore) ;no vc control files on Android devices + (write-region . tramp-adb-handle-write-region) + (set-file-modes . tramp-adb-handle-set-file-modes) + (set-file-times . ignore) + (copy-file . tramp-adb-handle-copy-file) + (rename-file . tramp-adb-handle-rename-file) + (process-file . tramp-adb-handle-process-file) + (shell-command . tramp-adb-handle-shell-command) + (start-file-process . tramp-adb-handle-start-file-process)) + "Alist of handler functions for Tramp ADB method.") + +;; It must be a `defsubst' in order to push the whole code into +;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading. +;;;###tramp-autoload +(defsubst tramp-adb-file-name-p (filename) + "Check if it's a filename for ADB." + (let ((v (tramp-dissect-file-name filename))) + (string= (tramp-file-name-method v) tramp-adb-method))) + +;;;###tramp-autoload +(defun tramp-adb-file-name-handler (operation &rest args) + "Invoke the ADB handler for OPERATION. +First arg specifies the OPERATION, second arg is a list of arguments to +pass to the OPERATION." + (let ((fn (assoc operation tramp-adb-file-name-handler-alist)) + ;; `tramp-default-host's default value is (system-name). Not + ;; useful for us. + (tramp-default-host + (unless (equal (eval (car (get 'tramp-default-host 'standard-value))) + tramp-default-host) + tramp-default-host))) + (if fn + (save-match-data (apply (cdr fn) args)) + (tramp-run-real-handler operation args)))) + +;; This cannot be a constant, because `tramp-adb-sdk-dir' is customizable. +(defun tramp-adb-program () + "The Android Debug Bridge." + (expand-file-name "platform-tools/adb" tramp-adb-sdk-dir)) + +;;;###tramp-autoload +(defun tramp-adb-parse-device-names (ignore) + "Return a list of (nil host) tuples allowed to access." + (with-temp-buffer + (when (zerop (call-process (tramp-adb-program) nil t nil "devices")) + (let (result) + (goto-char (point-min)) + (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t) + (add-to-list 'result (list nil (match-string 1)))) + result)))) + +(defun tramp-adb-handle-expand-file-name (name &optional dir) + "Like `expand-file-name' for Tramp files." + ;; If DIR is not given, use DEFAULT-DIRECTORY or "/". + (setq dir (or dir default-directory "/")) + ;; Unless NAME is absolute, concat DIR and NAME. + (unless (file-name-absolute-p name) + (setq name (concat (file-name-as-directory dir) name))) + ;; If NAME is not a Tramp file, run the real handler. + (if (not (tramp-tramp-file-p name)) + (tramp-run-real-handler 'expand-file-name (list name nil)) + ;; Dissect NAME. + (with-parsed-tramp-file-name name nil + (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))) + (tramp-make-tramp-file-name + method user host + (tramp-drop-volume-letter + (tramp-run-real-handler + 'expand-file-name (list localname)))))))) + +(defun tramp-adb-handle-file-directory-p (filename) + "Like `file-directory-p' for Tramp files." + (car (file-attributes (file-truename filename)))) + +;; This is derived from `tramp-sh-handle-file-truename'. Maybe the +;; code could be shared? +(defun tramp-adb-handle-file-truename (filename &optional counter prev-dirs) + "Like `file-truename' for Tramp files." + (with-parsed-tramp-file-name (expand-file-name filename) nil + (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 "/")) + (localnamedir (tramp-run-real-handler + 'file-name-as-directory (list localname))) + (is-dir (string= localname localnamedir)) + (thisstep nil) + (numchase 0) + ;; Don't make the following value larger than + ;; necessary. People expect an error message in a + ;; timely fashion when something is wrong; otherwise + ;; they might think that Emacs is hung. Of course, + ;; correctness has to come first. + (numchase-limit 20) + symlink-target) + (while (and steps (< numchase numchase-limit)) + (setq thisstep (pop steps)) + (tramp-message + v 5 "Check %s" + (mapconcat 'identity + (append '("") (reverse result) (list thisstep)) + "/")) + (setq symlink-target + (nth 0 (file-attributes + (tramp-make-tramp-file-name + method user host + (mapconcat 'identity + (append '("") + (reverse result) + (list thisstep)) + "/"))))) + (cond ((string= "." thisstep) + (tramp-message v 5 "Ignoring step `.'")) + ((string= ".." thisstep) + (tramp-message v 5 "Processing step `..'") + (pop result)) + ((stringp symlink-target) + ;; It's a symlink, follow it. + (tramp-message v 5 "Follow symlink to %s" symlink-target) + (setq numchase (1+ numchase)) + (when (file-name-absolute-p symlink-target) + (setq result nil)) + ;; If the symlink was absolute, we'll get a string + ;; like "/user@host:/some/target"; extract the + ;; "/some/target" part from it. + (when (tramp-tramp-file-p symlink-target) + (unless (tramp-equal-remote filename symlink-target) + (tramp-error + v 'file-error + "Symlink target `%s' on wrong host" symlink-target)) + (setq symlink-target localname)) + (setq steps + (append (tramp-compat-split-string + symlink-target "/") + steps))) + (t + ;; It's a file. + (setq result (cons thisstep result))))) + (when (>= numchase numchase-limit) + (tramp-error + v 'file-error + "Maximum number (%d) of symlinks exceeded" numchase-limit)) + (setq result (reverse result)) + ;; Combine list to form string. + (setq result + (if result + (mapconcat 'identity (cons "" result) "/") + "/")) + (when (and is-dir (or (string= "" result) + (not (string= (substring result -1) "/")))) + (setq result (concat result "/")))) + + (tramp-message v 4 "True name of `%s' is `%s'" filename result) + (tramp-make-tramp-file-name method user host result))))) + +(defun tramp-adb-handle-file-attributes (filename &optional id-format) + "Like `file-attributes' for Tramp files." + (unless id-format (setq id-format 'integer)) + (ignore-errors + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname (format "file-attributes-%s" id-format) + (tramp-adb-barf-unless-okay + v (format "ls -d -l %s" (tramp-shell-quote-argument localname)) "") + (with-current-buffer (tramp-get-buffer v) + (tramp-adb-sh-fix-ls-output) + (let* ((columns (split-string (buffer-string))) + (mod-string (nth 0 columns)) + (is-dir (eq ?d (aref mod-string 0))) + (is-symlink (eq ?l (aref mod-string 0))) + (symlink-target (and is-symlink (cadr (split-string (buffer-string) "\\( -> \\|\n\\)")))) + (uid (nth 1 columns)) + (gid (nth 2 columns)) + (date (format "%s %s" (nth 4 columns) (nth 5 columns))) + (size (string-to-number (nth 3 columns)))) + (list + (or is-dir symlink-target) + 1 ;link-count + ;; no way to handle numeric ids in Androids ash + (if (eq id-format 'integer) 0 uid) + (if (eq id-format 'integer) 0 gid) + '(0 0) ; atime + (date-to-time date) ; mtime + '(0 0) ; ctime + size + mod-string + ;; fake + t 1 1))))))) + +(defun tramp-adb--gnu-switches-to-ash + (switches) + "Almquist shell can't handle multiple arguments. +Convert (\"-al\") to (\"-a\" \"-l\"). Remove arguments like \"--dired\"." + (split-string + (apply 'concat + (mapcar (lambda (s) + (replace-regexp-in-string + "\\(.\\)" " -\\1" + (replace-regexp-in-string "^-" "" s))) + ;; FIXME: Warning about removed switches (long and non-dash). + (delq nil + (mapcar + (lambda (s) (and (not (string-match "\\(^--\\|^[^-]\\)" s)) s)) + switches)))))) + +(defun tramp-adb-handle-insert-directory + (filename switches &optional wildcard full-directory-p) + "Like `insert-directory' for Tramp files." + (when (stringp switches) + (setq switches (tramp-adb--gnu-switches-to-ash (split-string switches)))) + (with-parsed-tramp-file-name (file-truename filename) nil + (with-current-buffer (tramp-get-buffer v) + (let ((name (tramp-shell-quote-argument (directory-file-name localname))) + (switch-d (member "-d" switches)) + (switch-t (member "-t" switches)) + (switches (mapconcat 'identity (remove "-t" switches) " "))) + (tramp-adb-barf-unless-okay + v (format "ls %s %s" switches name) + "Cannot insert directory listing: %s" filename) + (unless switch-d + ;; We insert also filename/. and filename/.., because "ls" doesn't. + (narrow-to-region (point) (point)) + (ignore-errors + (tramp-adb-barf-unless-okay + v (format "ls -d %s %s %s" + switches + (concat (file-name-as-directory name) ".") + (concat (file-name-as-directory name) "..")) + "Cannot insert directory listing: %s" filename)) + (widen)) + (tramp-adb-sh-fix-ls-output switch-t))) + (insert-buffer-substring (tramp-get-buffer v)))) + +(defun tramp-adb-sh-fix-ls-output (&optional sort-by-time) + "Androids ls command doesn't insert size column for directories: Emacs dired can't find files. Insert dummy 0 in empty size columns." + (save-excursion + ;; Insert missing size. + (goto-char (point-min)) + (while (search-forward-regexp "[[:space:]]\\([[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]]\\)" nil t) + (replace-match "0\\1" "\\1" nil) + ;; Insert missing "/". + (when (looking-at "[0-9][0-9]:[0-9][0-9][[:space:]]+$") + (end-of-line) + (insert "/"))) + ;; Sort entries. + (let* ((lines (split-string (buffer-string) "\n" t)) + (sorted-lines + (sort + lines + (if sort-by-time + 'tramp-adb-ls-output-time-less-p + 'tramp-adb-ls-output-name-less-p)))) + (delete-region (point-min) (point-max)) + (insert " " (mapconcat 'identity sorted-lines "\n "))) + ;; Add final newline. + (goto-char (point-max)) + (unless (= (point) (line-beginning-position)) + (insert "\n")))) + + +(defun tramp-adb-ls-output-time-less-p (a b) + "Sort \"ls\" output by time, descending." + (let (time-a time-b) + (string-match tramp-adb-ls-date-regexp a) + (setq time-a (apply 'encode-time (parse-time-string (match-string 0 a)))) + (string-match tramp-adb-ls-date-regexp b) + (setq time-b (apply 'encode-time (parse-time-string (match-string 0 b)))) + (time-less-p time-b time-a))) + +(defun tramp-adb-ls-output-name-less-p (a b) + "Sort \"ls\" output by name, ascending." + (let (posa posb) + (string-match dired-move-to-filename-regexp a) + (setq posa (match-end 0)) + (string-match dired-move-to-filename-regexp b) + (setq 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." + (setq dir (expand-file-name dir)) + (with-parsed-tramp-file-name dir nil + (when parents + (let ((par (expand-file-name ".." dir))) + (unless (file-directory-p par) + (make-directory par parents)))) + (tramp-adb-barf-unless-okay + v (format "mkdir %s" (tramp-shell-quote-argument localname)) + "Couldn't make directory %s" dir) + (tramp-flush-directory-property v (file-name-directory localname)))) + +(defun tramp-adb-handle-delete-directory (directory &optional recursive) + "Like `delete-directory' for Tramp files." + (setq directory (expand-file-name directory)) + (with-parsed-tramp-file-name directory nil + (tramp-flush-file-property v (file-name-directory localname)) + (tramp-flush-directory-property v localname) + (tramp-adb-barf-unless-okay + v (format "%s %s" + (if recursive "rm -r" "rmdir") + (tramp-shell-quote-argument localname)) + "Couldn't delete %s" directory))) + +(defun tramp-adb-handle-delete-file (filename &optional trash) + "Like `delete-file' for Tramp files." + (setq filename (expand-file-name filename)) + (with-parsed-tramp-file-name filename nil + (tramp-flush-file-property v (file-name-directory localname)) + (tramp-flush-file-property v localname) + (tramp-adb-barf-unless-okay + v (format "rm %s" (tramp-shell-quote-argument localname)) + "Couldn't delete %s" filename))) + +(defun tramp-adb-handle-file-name-all-completions (filename directory) + "Like `file-name-all-completions' for Tramp files." + (all-completions + filename + (with-parsed-tramp-file-name directory nil + (with-tramp-file-property v localname "file-name-all-completions" + (save-match-data + (tramp-adb-send-command + v (format "ls %s" (tramp-shell-quote-argument localname))) + (mapcar + (lambda (f) + (if (file-directory-p f) + (file-name-as-directory f) + f)) + (with-current-buffer (tramp-get-buffer v) + (delq + nil + (mapcar + (lambda (l) (and (not (string-match "^[[:space:]]*$" l)) l)) + (split-string (buffer-string) "\n")))))))))) + +(defun tramp-adb-handle-file-local-copy (filename) + "Like `file-local-copy' for Tramp files." + (with-parsed-tramp-file-name filename nil + (unless (file-exists-p (file-truename filename)) + (tramp-error + v 'file-error + "Cannot make local copy of non-existing file `%s'" filename)) + (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) + (tramp-error + v 'file-error "Cannot make local copy of file `%s'" filename)) + (set-file-modes tmpfile (file-modes filename))) + tmpfile))) + +(defun tramp-adb-handle-file-writable-p (filename) + "Like `tramp-sh-handle-file-writable-p'. +But handle the case, if the \"test\" command is not available." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-writable-p" + (if (tramp-adb-find-test-command v) + (if (file-exists-p filename) + (zerop + (tramp-adb-command-exit-status + v (format "test -w %s" (tramp-shell-quote-argument localname)))) + (and + (file-directory-p (file-name-directory filename)) + (file-writable-p (file-name-directory filename)))) + + ;; Missing "test" command on Android < 4. + (let ((rw-path "/data/data")) + (tramp-message + v 5 + "Not implemented yet (assuming \"/data/data\" is writable): %s" + localname) + (and (>= (length localname) (length rw-path)) + (string= (substring localname 0 (length rw-path)) + rw-path))))))) + +(defun tramp-adb-handle-write-region + (start end filename &optional append visit lockname confirm) + "Like `write-region' for Tramp files." + (setq filename (expand-file-name filename)) + (with-parsed-tramp-file-name filename nil + (when append + (tramp-error + v 'file-error "Cannot append to file using Tramp (`%s')" filename)) + (when (and confirm (file-exists-p filename)) + (unless (y-or-n-p (format "File %s exists; overwrite anyway? " + filename)) + (tramp-error v 'file-error "File not overwritten"))) + ;; We must also flush the cache of the directory, because + ;; `file-attributes' reads the values from there. + (tramp-flush-file-property v (file-name-directory localname)) + (tramp-flush-file-property v localname) + (let* ((curbuf (current-buffer)) + (tmpfile (tramp-compat-make-temp-file filename))) + (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) + (unwind-protect + (when (tramp-adb-execute-adb-command v "push" tmpfile localname) + (tramp-error v 'file-error "Cannot write: `%s' filename")) + (delete-file tmpfile))) + + (unless (equal curbuf (current-buffer)) + (tramp-error + v 'file-error + "Buffer has changed from `%s' to `%s'" curbuf (current-buffer)))))) + +(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 localname) + (tramp-adb-barf-unless-okay + v (format "chmod %s %s" (tramp-compat-decimal-to-octal mode) localname) + "Error while changing file's mode %s" filename))) + +(defun tramp-adb-handle-copy-file + (filename newname &optional ok-if-already-exists keep-date + preserve-uid-gid preserve-selinux-context) + "Like `copy-file' for Tramp files. +PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored." + (setq filename (expand-file-name filename) + newname (expand-file-name newname)) + + (if (file-directory-p filename) + (copy-directory filename newname keep-date t) + (with-tramp-progress-reporter + (tramp-dissect-file-name (if (file-remote-p filename) filename newname)) + 0 (format "Copying %s to %s" filename newname) + + (let ((tmpfile (file-local-copy filename))) + + (if tmpfile + ;; Remote filename. + (condition-case err + (rename-file tmpfile newname ok-if-already-exists) + ((error quit) + (delete-file tmpfile) + (signal (car err) (cdr err)))) + + ;; Remote newname. + (when (file-directory-p newname) + (setq newname + (expand-file-name (file-name-nondirectory filename) newname))) + + (with-parsed-tramp-file-name newname nil + (when (and (not ok-if-already-exists) + (file-exists-p newname)) + (tramp-error v 'file-already-exists newname)) + + ;; We must also flush the cache of the directory, because + ;; `file-attributes' reads the values from there. + (tramp-flush-file-property v (file-name-directory localname)) + (tramp-flush-file-property v localname) + (when (tramp-adb-execute-adb-command v "push" filename localname) + (tramp-error + v 'file-error "Cannot copy `%s' `%s'" filename newname)))))) + + ;; KEEP-DATE handling. + (when keep-date + (set-file-times newname (nth 5 (file-attributes filename)))))) + +(defun tramp-adb-handle-rename-file + (filename newname &optional ok-if-already-exists) + "Like `rename-file' for Tramp files." + (setq filename (expand-file-name filename) + newname (expand-file-name newname)) + + (with-parsed-tramp-file-name + (if (file-remote-p filename) filename newname) nil + (with-tramp-progress-reporter + v 0 (format "Renaming %s to %s" newname filename) + + (if (and (tramp-equal-remote filename newname) + (not (file-directory-p filename))) + (progn + (when (and (not ok-if-already-exists) + (file-exists-p newname)) + (tramp-error v 'file-already-exists newname)) + ;; We must also flush the cache of the directory, because + ;; `file-attributes' reads the values from there. + (tramp-flush-file-property v (file-name-directory localname)) + (tramp-flush-file-property v localname) + ;; Short track. + (tramp-adb-barf-unless-okay + v (format "mv %s %s" (file-remote-p filename 'localname) localname) + "Error renaming %s to %s" filename newname)) + + ;; Rename by copy. + (copy-file filename newname ok-if-already-exists t t) + (delete-file filename))))) + +(defun tramp-adb-handle-process-file + (program &optional infile destination display &rest args) + "Like `process-file' for Tramp files." + ;; The implementation is not complete yet. + (when (and (numberp destination) (zerop destination)) + (error "Implementation does not handle immediate return")) + + (with-parsed-tramp-file-name default-directory nil + (let (command input tmpinput stderr tmpstderr outbuf ret) + ;; Compute command. + (setq command (mapconcat 'tramp-shell-quote-argument + (cons program args) " ")) + ;; Determine input. + (if (null infile) + (setq input "/dev/null") + (setq infile (expand-file-name infile)) + (if (tramp-equal-remote default-directory infile) + ;; INFILE is on the same remote host. + (setq input (with-parsed-tramp-file-name infile nil localname)) + ;; INFILE must be copied to remote host. + (setq input (tramp-make-tramp-temp-file v) + tmpinput (tramp-make-tramp-file-name method user host input)) + (copy-file infile tmpinput t))) + (when input (setq command (format "%s <%s" command input))) + + ;; Determine output. + (cond + ;; Just a buffer. + ((bufferp destination) + (setq outbuf destination)) + ;; A buffer name. + ((stringp destination) + (setq outbuf (get-buffer-create destination))) + ;; (REAL-DESTINATION ERROR-DESTINATION) + ((consp destination) + ;; output. + (cond + ((bufferp (car destination)) + (setq outbuf (car destination))) + ((stringp (car destination)) + (setq outbuf (get-buffer-create (car destination)))) + ((car destination) + (setq outbuf (current-buffer)))) + ;; stderr. + (cond + ((stringp (cadr destination)) + (setcar (cdr destination) (expand-file-name (cadr destination))) + (if (tramp-equal-remote default-directory (cadr destination)) + ;; stderr is on the same remote host. + (setq stderr (with-parsed-tramp-file-name + (cadr destination) nil localname)) + ;; stderr must be copied to remote host. The temporary + ;; file must be deleted after execution. + (setq stderr (tramp-make-tramp-temp-file v) + tmpstderr (tramp-make-tramp-file-name + method user host stderr)))) + ;; stderr to be discarded. + ((null (cadr destination)) + (setq stderr "/dev/null")))) + ;; 't + (destination + (setq outbuf (current-buffer)))) + (when stderr (setq command (format "%s 2>%s" command stderr))) + + ;; Send the command. It might not return in time, so we protect + ;; it. Call it in a subshell, in order to preserve working + ;; directory. + (condition-case nil + (progn + (setq ret 0 + ret + (tramp-adb-barf-unless-okay + v (format "(cd %s; %s)" + (tramp-shell-quote-argument localname) + command) + "")) + ;; We should show the output anyway. + (when outbuf + (with-current-buffer outbuf + (insert-buffer-substring (tramp-get-connection-buffer v))) + (when display (display-buffer outbuf)))) + ;; When the user did interrupt, we should do it also. We use + ;; return code -1 as marker. + (quit + (kill-buffer (tramp-get-connection-buffer v)) + (setq ret -1)) + ;; Handle errors. + (error + (kill-buffer (tramp-get-connection-buffer v)) + (setq ret 1))) + + ;; Provide error file. + (when tmpstderr (rename-file tmpstderr (cadr destination) t)) + + ;; Cleanup. We remove all file cache values for the connection, + ;; 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))) + (tramp-flush-directory-property v "")) + + ;; Return exit status. + (if (equal ret -1) + (keyboard-quit) + ret)))) + +(defun tramp-adb-handle-shell-command + (command &optional output-buffer error-buffer) + "Like `shell-command' for Tramp files." + (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command)) + ;; We cannot use `shell-file-name' and `shell-command-switch', + ;; they are variables of the local host. + (args (list "sh" "-c" (substring command 0 asynchronous))) + current-buffer-p + (output-buffer + (cond + ((bufferp output-buffer) output-buffer) + ((stringp output-buffer) (get-buffer-create output-buffer)) + (output-buffer + (setq current-buffer-p t) + (current-buffer)) + (t (get-buffer-create + (if asynchronous + "*Async Shell Command*" + "*Shell Command Output*"))))) + (error-buffer + (cond + ((bufferp error-buffer) error-buffer) + ((stringp error-buffer) (get-buffer-create error-buffer)))) + (buffer + (if (and (not asynchronous) error-buffer) + (with-parsed-tramp-file-name default-directory nil + (list output-buffer (tramp-make-tramp-temp-file v))) + output-buffer)) + (p (get-buffer-process output-buffer))) + + ;; Check whether there is another process running. Tramp does not + ;; support 2 (asynchronous) processes in parallel. + (when p + (if (yes-or-no-p "A command is running. Kill it? ") + (ignore-errors (kill-process p)) + (error "Shell command in progress"))) + + (if current-buffer-p + (progn + (barf-if-buffer-read-only) + (push-mark nil t)) + (with-current-buffer output-buffer + (setq buffer-read-only nil) + (erase-buffer))) + + (if (and (not current-buffer-p) (integerp asynchronous)) + (prog1 + ;; Run the process. + (apply 'start-file-process "*Async Shell*" buffer args) + ;; Display output. + (pop-to-buffer output-buffer) + (setq mode-line-process '(":%s")) + (shell-mode)) + + (prog1 + ;; Run the process. + (apply 'process-file (car args) nil buffer nil (cdr args)) + ;; Insert error messages if they were separated. + (when (listp buffer) + (with-current-buffer error-buffer + (insert-file-contents (cadr buffer))) + (delete-file (cadr buffer))) + (if current-buffer-p + ;; This is like exchange-point-and-mark, but doesn't + ;; activate the mark. It is cleaner to avoid activation, + ;; even though the command loop would deactivate the mark + ;; because we inserted text. + (goto-char (prog1 (mark t) + (set-marker (mark-marker) (point) + (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)))))))) + +;; We use BUFFER also as connection buffer during setup. Because of +;; this, its original contents must be saved, and restored once +;; connection has been setup. +(defun tramp-adb-handle-start-file-process (name buffer program &rest args) + "Like `start-file-process' for Tramp files." + (with-parsed-tramp-file-name default-directory nil + ;; When PROGRAM is nil, we just provide a tty. + (let ((command + (when (stringp program) + (format "cd %s; %s" + (tramp-shell-quote-argument localname) + (mapconcat 'tramp-shell-quote-argument + (cons program args) " ")))) + (tramp-process-connection-type + (or (null program) tramp-process-connection-type)) + (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer))) + (name1 name) + (i 0)) + (unwind-protect + (save-excursion + (save-restriction + (unless buffer + ;; BUFFER can be nil. We use a temporary buffer. + (setq buffer (generate-new-buffer tramp-temp-buffer-name))) + (while (get-process name1) + ;; NAME must be unique as process name. + (setq i (1+ i) + name1 (format "%s<%d>" name i))) + (setq name name1) + ;; Set the new process properties. + (tramp-set-connection-property v "process-name" name) + (tramp-set-connection-property v "process-buffer" buffer) + ;; Activate narrowing in order to save BUFFER contents. + ;; Clear also the modification time; otherwise we might + ;; be interrupted by `verify-visited-file-modtime'. + (with-current-buffer (tramp-get-connection-buffer v) + (let ((buffer-undo-list t)) + (clear-visited-file-modtime) + (narrow-to-region (point-max) (point-max)) + (if command + ;; Send the command. + (tramp-adb-send-command v command) + ;; Open the connection. + (tramp-adb-maybe-open-connection v)))) + (let ((p (tramp-get-connection-process v))) + ;; Set sentinel and query flag for this process. + (tramp-set-connection-property p "vector" v) + (set-process-sentinel p 'tramp-process-sentinel) + (tramp-compat-set-process-query-on-exit-flag p t) + ;; Return process. + p))) + ;; Save exit. + (with-current-buffer (tramp-get-connection-buffer v) + (if (string-match tramp-temp-buffer-name (buffer-name)) + (progn + (set-process-buffer (tramp-get-connection-process v) nil) + (kill-buffer (current-buffer))) + (set-buffer-modified-p bmp))) + (tramp-set-connection-property v "process-name" nil) + (tramp-set-connection-property v "process-buffer" nil))))) + +;; Android < 4 doesn't provide test command. + +(defun tramp-adb-handle-file-exists-p (filename) + "Like `file-exists-p' for Tramp files." + (with-parsed-tramp-file-name filename nil + (with-tramp-file-property v localname "file-exists-p" + (file-attributes filename)))) + +;; Helper functions. + +(defun tramp-adb-execute-adb-command (vec &rest args) + "Returns nil on success error-output on failure." + (when (tramp-file-name-host vec) + (setq args (append (list "-s" (tramp-file-name-host vec)) args))) + (with-temp-buffer + (prog1 + (unless (zerop (apply 'call-process (tramp-adb-program) nil t nil args)) + (buffer-string)) + (tramp-message + vec 6 "%s %s\n%s" + (tramp-adb-program) (mapconcat 'identity args " ") (buffer-string))))) + +(defun tramp-adb-find-test-command (vec) + "Checks, whether the ash has a builtin \"test\" command. +This happens for Android >= 4.0." + (with-tramp-connection-property vec "test" + (zerop (tramp-adb-command-exit-status vec "type test")))) + +;; Connection functions + +(defun tramp-adb-send-command (vec command) + "Send the COMMAND to connection VEC." + (tramp-adb-maybe-open-connection vec) + (tramp-message vec 6 "%s" command) + (tramp-send-string vec command) + ;; fixme: Race condition + (tramp-adb-wait-for-output (tramp-get-connection-process vec)) + (with-current-buffer (tramp-get-connection-buffer vec) + (save-excursion + (goto-char (point-min)) + ;; We can't use stty to disable echo of command. + (delete-matching-lines (regexp-quote command)) + ;; When the local machine is W32, there are still trailing ^M. + ;; There must be a better solution by setting the correct coding + ;; system, but this requires changes in core Tramp. + (goto-char (point-min)) + (while (re-search-forward "\r+$" nil t) + (replace-match "" nil nil))))) + +(defun tramp-adb-barf-unless-okay (vec command fmt &rest args) + "Run COMMAND, check exit status, throw error if exit status not okay. +FMT and ARGS are passed to `error'." + (tramp-adb-send-command vec (format "%s; echo tramp_exit_status $?" command)) + (with-current-buffer (tramp-get-connection-buffer vec) + (goto-char (point-max)) + (unless (re-search-backward "tramp_exit_status [0-9]+" nil t) + (tramp-error + vec 'file-error "Couldn't find exit status of `%s'" command)) + (skip-chars-forward "^ ") + (unless (zerop (read (current-buffer))) + (apply 'tramp-error vec 'file-error fmt args)) + (let (buffer-read-only) + (delete-region (match-beginning 0) (point-max))))) + +(defun tramp-adb-command-exit-status + (vec command) + "Run COMMAND and return its exit status. +Sends `echo $?' along with the COMMAND for checking the exit status. If +COMMAND is nil, just sends `echo $?'. Returns the exit status found." + (tramp-adb-send-command vec (format "%s; echo tramp_exit_status $?" command)) + (with-current-buffer (tramp-get-connection-buffer vec) + (goto-char (point-max)) + (unless (re-search-backward "tramp_exit_status [0-9]+" nil t) + (tramp-error + vec 'file-error "Couldn't find exit status of `%s'" command)) + (skip-chars-forward "^ ") + (read (current-buffer)))) + +(defun tramp-adb-wait-for-output (proc &optional timeout) + "Wait for output from remote command." + (unless (buffer-live-p (process-buffer proc)) + (delete-process proc) + (tramp-error proc 'file-error "Process `%s' not available, try again" proc)) + (with-current-buffer (process-buffer proc) + (if (tramp-wait-for-regexp proc timeout tramp-adb-prompt) + (let (buffer-read-only) + (goto-char (point-min)) + ;; ADB terminal sends "^H" sequences. + (when (re-search-forward "<\b+" (point-at-eol) t) + (forward-line 1) + (delete-region (point-min) (point))) + ;; Delete the prompt. + (goto-char (point-min)) + (when (re-search-forward tramp-adb-prompt (point-at-eol) t) + (forward-line 1) + (delete-region (point-min) (point))) + (goto-char (point-max)) + (re-search-backward tramp-adb-prompt nil t) + (delete-region (point) (point-max))) + (if timeout + (tramp-error + proc 'file-error + "[[Remote adb prompt `%s' not found in %d secs]]" + tramp-adb-prompt timeout) + (tramp-error + proc 'file-error + "[[Remote prompt `%s' not found]]" tramp-adb-prompt))))) + +(defun tramp-adb-maybe-open-connection (vec) + "Maybe open a connection VEC. +Does not do anything if a connection is already open, but re-opens the +connection if a previous connection has died for some reason." + (let* ((buf (tramp-get-connection-buffer vec)) + (p (get-buffer-process buf))) + (unless + (and p (processp p) (memq (process-status p) '(run open))) + (save-match-data + (when (and p (processp p)) (delete-process p)) + (with-tramp-progress-reporter vec 3 "Opening adb shell connection" + (let* ((coding-system-for-read 'utf-8-dos) ;is this correct? + (process-connection-type tramp-process-connection-type) + (args (if (tramp-file-name-host vec) + (list "-s" (tramp-file-name-host vec) "shell") + (list "shell"))) + (p (let ((default-directory + (tramp-compat-temporary-file-directory))) + (apply 'start-process (tramp-get-connection-name vec) buf + (tramp-adb-program) args)))) + (tramp-message + vec 6 "%s" (mapconcat 'identity (process-command p) " ")) + ;; Wait for initial prompt. + (tramp-adb-wait-for-output p) + (unless (eq 'run (process-status p)) + (tramp-error vec 'file-error "Terminated!")) + (set-process-query-on-exit-flag p nil))))))) + +(provide 'tramp-adb) +;;; tramp-adb.el ends here diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index fe5eb0049d0..e4fca46ce2d 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -139,27 +139,6 @@ Returns VALUE." value)) ;;;###tramp-autoload -(defmacro with-file-property (vec file property &rest body) - "Check in Tramp cache for PROPERTY, otherwise execute BODY and set cache. -FILE must be a local file name on a connection identified via VEC." - `(if (file-name-absolute-p ,file) - (let ((value (tramp-get-file-property ,vec ,file ,property 'undef))) - (when (eq value 'undef) - ;; We cannot pass @body as parameter to - ;; `tramp-set-file-property' because it mangles our - ;; debug messages. - (setq value (progn ,@body)) - (tramp-set-file-property ,vec ,file ,property value)) - value) - ,@body)) - -;;;###tramp-autoload -(put 'with-file-property 'lisp-indent-function 3) -(put 'with-file-property 'edebug-form-spec t) -(tramp-compat-font-lock-add-keywords - 'emacs-lisp-mode '("\\<with-file-property\\>")) - -;;;###tramp-autoload (defun tramp-flush-file-property (vec file) "Remove all properties of FILE in the cache context of VEC." ;; Remove file property of symlinks. @@ -250,24 +229,6 @@ PROPERTY is set persistent when KEY is a vector." value)) ;;;###tramp-autoload -(defmacro with-connection-property (key property &rest body) - "Check in Tramp for property PROPERTY, otherwise executes BODY and set." - `(let ((value (tramp-get-connection-property ,key ,property 'undef))) - (when (eq value 'undef) - ;; We cannot pass ,@body as parameter to - ;; `tramp-set-connection-property' because it mangles our debug - ;; messages. - (setq value (progn ,@body)) - (tramp-set-connection-property ,key ,property value)) - value)) - -;;;###tramp-autoload -(put 'with-connection-property 'lisp-indent-function 2) -(put 'with-connection-property 'edebug-form-spec t) -(tramp-compat-font-lock-add-keywords - 'emacs-lisp-mode '("\\<with-connection-property\\>")) - -;;;###tramp-autoload (defun tramp-flush-connection-property (key) "Remove all properties identified by KEY. KEY identifies the connection, it is either a process or a vector." diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el index 06aae1f6af2..abca6b3ea01 100644 --- a/lisp/net/tramp-cmds.el +++ b/lisp/net/tramp-cmds.el @@ -204,7 +204,7 @@ useful thing to do is to put (setq tramp-verbose 9) -in the ~/.emacs file and to repeat the bug. Then, include the +in your init file and to repeat the bug. Then, include the contents of the *tramp/foo* buffer and the *debug tramp/foo* buffer in your bug report. diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index c3552ae023b..3d37a0cfc39 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -71,22 +71,6 @@ (require 'timer-funcs) (require 'timer)) - ;; We check whether `start-file-process' is bound. - ;; Note: we deactivate this. There are problems, at least in SXEmacs. - (unless t;(fboundp 'start-file-process) - - ;; tramp-util offers integration into other (X)Emacs packages like - ;; compile.el, gud.el etc. Not necessary in Emacs 23. - (eval-after-load "tramp" - '(require 'tramp-util)) - - ;; Make sure that we get integration with the VC package. When it - ;; is loaded, we need to pull in the integration module. Not - ;; necessary in Emacs 23. - (eval-after-load "vc" - (eval-after-load "tramp" - '(require 'tramp-vc)))) - ;; Avoid byte-compiler warnings if the byte-compiler supports this. ;; Currently, XEmacs supports this. (when (featurep 'xemacs) @@ -132,9 +116,7 @@ ;; mechanism. ;; `file-remote-p' has been introduced with Emacs 22. The version - ;; of XEmacs is not a magic file name function (yet); this is - ;; corrected in tramp-util.el. Here it is sufficient if the - ;; function exists. + ;; of XEmacs is not a magic file name function (yet). (unless (fboundp 'file-remote-p) (defalias 'file-remote-p (lambda (file &optional identification connected) diff --git a/lisp/net/tramp-ftp.el b/lisp/net/tramp-ftp.el index 44ae176c6c9..77e36292ef9 100644 --- a/lisp/net/tramp-ftp.el +++ b/lisp/net/tramp-ftp.el @@ -200,6 +200,8 @@ pass to the OPERATION." (inhibit-file-name-operation operation)) (apply 'ange-ftp-hook-function operation args))))))) +;; It must be a `defsubst' in order to push the whole code into +;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading. ;;;###tramp-autoload (defsubst tramp-ftp-file-name-p (filename) "Check if it's a filename that should be forwarded to Ange-FTP." diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index f78122ec704..1467aede2c3 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -432,6 +432,8 @@ Every entry is a list (NAME ADDRESS).") "Alist of handler functions for Tramp GVFS method. Operations not mentioned here will be handled by the default Emacs primitives.") +;; It must be a `defsubst' in order to push the whole code into +;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading. ;;;###tramp-autoload (defsubst tramp-gvfs-file-name-p (filename) "Check if it's a filename handled by the GVFS daemon." @@ -521,12 +523,16 @@ It is needed when D-Bus signals or errors arrive, because there is no information where to trace the message.") (defun tramp-gvfs-dbus-event-error (event err) - "Called when a D-Bus error message arrives, see `dbus-event-error-hooks'." + "Called when a D-Bus error message arrives, see `dbus-event-error-functions'." (when tramp-gvfs-dbus-event-vector (tramp-message tramp-gvfs-dbus-event-vector 10 "%S" event) (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err)))) -(add-hook 'dbus-event-error-hooks 'tramp-gvfs-dbus-event-error) +;; `dbus-event-error-hooks' has been renamed to `dbus-event-error-functions'. +(add-hook + (if (boundp 'dbus-event-error-functions) + 'dbus-event-error-functions 'dbus-event-error-hooks) + 'tramp-gvfs-dbus-event-error) ;; File name primitives. @@ -537,7 +543,7 @@ is no information where to trace the message.") "Like `copy-file' for Tramp files." (with-parsed-tramp-file-name (if (tramp-tramp-file-p filename) filename newname) nil - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 0 (format "Copying %s to %s" filename newname) (condition-case err (let ((args @@ -741,7 +747,7 @@ is no information where to trace the message.") "Like `rename-file' for Tramp files." (with-parsed-tramp-file-name (if (tramp-tramp-file-p filename) filename newname) nil - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 0 (format "Renaming %s to %s" filename newname) (condition-case err (rename-file @@ -1056,7 +1062,7 @@ ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"." (catch 'mounted (dolist (elt - (with-file-property vec "/" "list-mounts" + (with-tramp-file-property vec "/" "list-mounts" (with-tramp-dbus-call-method vec t :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker tramp-gvfs-interface-mounttracker "listMounts")) @@ -1199,7 +1205,7 @@ connection if a previous connection has died for some reason." (tramp-gvfs-object-path (tramp-make-tramp-file-name method user host "")))) - (tramp-with-progress-reporter + (with-tramp-progress-reporter vec 3 (if (zerop (length user)) (format "Opening connection for %s using %s" host method) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 2c1af3e83fa..3008601d9ca 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -813,14 +813,11 @@ my %%trans = do { map {(substr(unpack(q(B8), chr $i++), 2, 6), $_)} split //, q(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/); }; - -binmode(\\*STDIN); +my $data; # We read in chunks of 54 bytes, to generate output lines # of 72 chars (plus end of line) -$/ = \\54; - -while (my $data = <STDIN>) { +while (read STDIN, $data, 54) { my $pad = q(); # Only for the last chunk, and only if did not fill the last three-byte packet @@ -1058,7 +1055,7 @@ target of the symlink differ." "Like `file-truename' for Tramp files." (with-parsed-tramp-file-name (expand-file-name filename) nil (tramp-make-tramp-file-name method user host - (with-file-property v localname "file-truename" + (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) (cond @@ -1167,7 +1164,7 @@ target of the symlink differ." (defun tramp-sh-handle-file-exists-p (filename) "Like `file-exists-p' for Tramp files." (with-parsed-tramp-file-name filename nil - (with-file-property v localname "file-exists-p" + (with-tramp-file-property v localname "file-exists-p" (or (not (null (tramp-get-file-property v localname "file-attributes-integer" nil))) (not (null (tramp-get-file-property @@ -1185,7 +1182,8 @@ target of the symlink differ." ;; Don't modify `last-coding-system-used' by accident. (let ((last-coding-system-used last-coding-system-used)) (with-parsed-tramp-file-name (expand-file-name filename) nil - (with-file-property v localname (format "file-attributes-%s" id-format) + (with-tramp-file-property + v localname (format "file-attributes-%s" id-format) (save-excursion (tramp-convert-file-attributes v @@ -1269,9 +1267,10 @@ target of the symlink differ." res-uid ;; 3. File gid. res-gid - ;; 4. Last access time, as a list of two integers. First - ;; integer has high-order 16 bits of time, second has low 16 - ;; bits. + ;; 4. Last access time, as a list of integers. Normally this + ;; would be in the same format as `current-time', but the + ;; subseconds part is not currently implemented, and (0 0) + ;; denotes an unknown time. ;; 5. Last modification time, likewise. ;; 6. Last status change time, likewise. '(0 0) '(0 0) '(0 0) ;CCC how to find out? @@ -1481,7 +1480,8 @@ and gid of the corresponding user is taken. Both parameters must be integers." (defun tramp-remote-selinux-p (vec) "Check, whether SELINUX is enabled on the remote host." - (with-connection-property (tramp-get-connection-process vec) "selinux-p" + (with-tramp-connection-property + (tramp-get-connection-process vec) "selinux-p" (let ((result (tramp-find-executable vec "getenforce" (tramp-get-remote-path vec) t t))) (and result @@ -1493,7 +1493,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." (defun tramp-sh-handle-file-selinux-context (filename) "Like `file-selinux-context' for Tramp files." (with-parsed-tramp-file-name filename nil - (with-file-property v localname "file-selinux-context" + (with-tramp-file-property v localname "file-selinux-context" (let ((context '(nil nil nil nil)) (regexp (concat "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\)"))) @@ -1537,7 +1537,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." (defun tramp-sh-handle-file-executable-p (filename) "Like `file-executable-p' for Tramp files." (with-parsed-tramp-file-name filename nil - (with-file-property v localname "file-executable-p" + (with-tramp-file-property v localname "file-executable-p" ;; Examine `file-attributes' cache to see if request can be ;; satisfied without remote operation. (or (tramp-check-cached-permissions v ?x) @@ -1546,7 +1546,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." (defun tramp-sh-handle-file-readable-p (filename) "Like `file-readable-p' for Tramp files." (with-parsed-tramp-file-name filename nil - (with-file-property v localname "file-readable-p" + (with-tramp-file-property v localname "file-readable-p" ;; Examine `file-attributes' cache to see if request can be ;; satisfied without remote operation. (or (tramp-check-cached-permissions v ?r) @@ -1600,13 +1600,13 @@ and gid of the corresponding user is taken. Both parameters must be integers." ;; desirable to return t immediately for "/method:foo:". It can ;; be expected that this is always a directory. (or (zerop (length localname)) - (with-file-property v localname "file-directory-p" + (with-tramp-file-property v localname "file-directory-p" (tramp-run-test "-d" filename))))) (defun tramp-sh-handle-file-writable-p (filename) "Like `file-writable-p' for Tramp files." (with-parsed-tramp-file-name filename nil - (with-file-property v localname "file-writable-p" + (with-tramp-file-property v localname "file-writable-p" (if (file-exists-p filename) ;; Examine `file-attributes' cache to see if request can be ;; satisfied without remote operation. @@ -1616,15 +1616,18 @@ and gid of the corresponding user is taken. Both parameters must be integers." (and (tramp-run-test "-d" (file-name-directory filename)) (tramp-run-test "-w" (file-name-directory filename))))))) -(defun tramp-sh-handle-file-ownership-preserved-p (filename) +(defun tramp-sh-handle-file-ownership-preserved-p (filename &optional group) "Like `file-ownership-preserved-p' for Tramp files." (with-parsed-tramp-file-name filename nil - (with-file-property v localname "file-ownership-preserved-p" + (with-tramp-file-property v localname "file-ownership-preserved-p" (let ((attributes (file-attributes filename))) ;; Return t if the file doesn't exist, since it's true that no ;; information would be lost by an (attempted) delete and create. (or (null attributes) - (= (nth 2 attributes) (tramp-get-remote-uid v 'integer))))))) + (and + (= (nth 2 attributes) (tramp-get-remote-uid v 'integer)) + (or (not group) + (= (nth 3 attributes) (tramp-get-remote-gid v 'integer))))))))) ;; Directory listings. @@ -1637,7 +1640,7 @@ and gid of the corresponding user is taken. Both parameters must be integers." (let* ((temp (copy-tree (with-parsed-tramp-file-name directory nil - (with-file-property + (with-tramp-file-property v localname (format "directory-files-and-attributes-%s" id-format) (save-excursion @@ -1978,6 +1981,7 @@ file names." (error "Unknown operation `%s', must be `copy' or `rename'" op)) (let ((t1 (tramp-tramp-file-p filename)) (t2 (tramp-tramp-file-p newname)) + (length (nth 7 (file-attributes (file-truename filename)))) (context (and preserve-selinux-context (apply 'file-selinux-context (list filename)))) pr tm) @@ -1987,7 +1991,7 @@ file names." (tramp-error v 'file-already-exists "File %s already exists" newname)) - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 0 (format "%s %s to %s" (if (eq op 'copy) "Copying" "Renaming") filename newname) @@ -2007,8 +2011,9 @@ file names." ok-if-already-exists keep-date preserve-uid-gid)) ;; Try out-of-band operation. - ((tramp-method-out-of-band-p - v1 (nth 7 (file-attributes (file-truename filename)))) + ((and + (tramp-method-out-of-band-p v1 length) + (tramp-method-out-of-band-p v2 length)) (tramp-do-copy-or-rename-file-out-of-band op filename newname keep-date)) @@ -2036,8 +2041,7 @@ file names." ;; If the Tramp file has an out-of-band method, the ;; corresponding copy-program can be invoked. - ((tramp-method-out-of-band-p - v (nth 7 (file-attributes (file-truename filename)))) + ((tramp-method-out-of-band-p v length) (tramp-do-copy-or-rename-file-out-of-band op filename newname keep-date)) @@ -2378,17 +2382,38 @@ The method used must be an out-of-band method." ;; last longer than 60 secs. (let ((p (let ((default-directory (tramp-compat-temporary-file-directory))) - (apply 'start-process + (apply 'start-process-shell-command (tramp-get-connection-name v) (tramp-get-connection-buffer v) copy-program - (append copy-args (list source target)))))) + (append + copy-args + (list + (shell-quote-argument source) + (shell-quote-argument target) + "&&" "echo" "tramp_exit_status" "0" + "||" "echo" "tramp_exit_status" "1")))))) (tramp-message orig-vec 6 "%s" (mapconcat 'identity (process-command p) " ")) (tramp-compat-set-process-query-on-exit-flag p nil) (tramp-process-actions - p v nil tramp-actions-copy-out-of-band))) + p v nil tramp-actions-copy-out-of-band) + + ;; Check the return code. + (goto-char (point-max)) + (unless + (re-search-backward "tramp_exit_status [0-9]+" nil t) + (tramp-error + orig-vec 'file-error + "Couldn't find exit status of `%s'" (process-command p))) + (skip-chars-forward "^ ") + (unless (zerop (read (current-buffer))) + (forward-line -1) + (tramp-error + orig-vec 'file-error + "Error copying: `%s'" + (buffer-substring (point-min) (point-at-eol)))))) ;; Reset the transfer process properties. (tramp-message orig-vec 6 "\n%s" (buffer-string)) @@ -2505,7 +2530,7 @@ This is like `dired-recursive-delete-directory' for Tramp files." nil) ((and suffix (nth 2 suffix)) ;; We found an uncompression rule. - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 0 (format "Uncompressing %s" file) (when (tramp-send-command-and-check v (concat (nth 2 suffix) " " @@ -2517,7 +2542,7 @@ This is like `dired-recursive-delete-directory' for Tramp files." (t ;; We don't recognize the file as compressed, so compress it. ;; Try gzip. - (tramp-with-progress-reporter v 0 (format "Compressing %s" file) + (with-tramp-progress-reporter v 0 (format "Compressing %s" file) (when (tramp-send-command-and-check v (concat "gzip -f " (tramp-shell-quote-argument localname))) @@ -2673,7 +2698,7 @@ the result will be a local, non-Tramp, filename." (string-match "\\`su\\(do\\)?\\'" method)) (setq uname (concat uname user))) (setq uname - (with-connection-property v uname + (with-tramp-connection-property v uname (tramp-send-command v (format "cd %s; pwd" (tramp-shell-quote-argument uname))) (with-current-buffer (tramp-get-buffer v) @@ -2910,16 +2935,6 @@ the result will be a local, non-Tramp, filename." (keyboard-quit) ret)))) -(defun tramp-sh-handle-call-process-region - (start end program &optional delete buffer display &rest args) - "Like `call-process-region' for Tramp files." - (let ((tmpfile (tramp-compat-make-temp-file ""))) - (write-region start end tmpfile) - (when delete (delete-region start end)) - (unwind-protect - (apply 'call-process program tmpfile buffer display args) - (delete-file tmpfile)))) - (defun tramp-sh-handle-file-local-copy (filename) "Like `file-local-copy' for Tramp files." (with-parsed-tramp-file-name filename nil @@ -2943,7 +2958,7 @@ the result will be a local, non-Tramp, filename." ;; Use inline encoding for file transfer. (rem-enc (save-excursion - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Encoding remote file %s" filename) (tramp-barf-unless-okay v (format rem-enc (tramp-shell-quote-argument localname)) @@ -2957,7 +2972,7 @@ the result will be a local, non-Tramp, filename." (with-temp-buffer (set-buffer-multibyte nil) (insert-buffer-substring (tramp-get-buffer v)) - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Decoding remote file %s with function %s" filename loc-dec) (funcall loc-dec (point-min) (point-max)) @@ -2975,7 +2990,7 @@ the result will be a local, non-Tramp, filename." (let (file-name-handler-alist (coding-system-for-write 'binary)) (write-region (point-min) (point-max) tmpfile2)) - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Decoding remote file %s with command %s" filename loc-dec) (unwind-protect @@ -3203,7 +3218,7 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file." (set-buffer-multibyte nil) ;; Use encoding function or command. (if (functionp loc-enc) - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Encoding region using function `%s'" loc-enc) (let ((coding-system-for-read 'binary)) @@ -3221,7 +3236,7 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file." (tramp-compat-temporary-file-directory))) (funcall loc-enc (point-min) (point-max)))) - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Encoding region using command `%s'" loc-enc) (unless (zerop (tramp-call-local-coding-command @@ -3235,7 +3250,7 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file." ;; Send buffer into remote decoding command which ;; writes to remote file. Because this happens on ;; the remote host, we cannot use the function. - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Decoding region into remote file %s" filename) (goto-char (point-max)) @@ -3335,7 +3350,7 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file." "Like `vc-registered' for Tramp files." (tramp-compat-with-temp-message "" (with-parsed-tramp-file-name file nil - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Checking `vc-registered' for %s" file) ;; There could be new files, created by the vc backend. We @@ -3433,7 +3448,7 @@ Only send the definition if it has not already been done." (let ((scripts (tramp-get-connection-property (tramp-get-connection-process vec) "scripts" nil))) (unless (member name scripts) - (tramp-with-progress-reporter vec 5 (format "Sending script `%s'" name) + (with-tramp-progress-reporter vec 5 (format "Sending script `%s'" name) ;; The script could contain a call of Perl. This is masked with `%s'. (tramp-barf-unless-okay vec @@ -3602,7 +3617,7 @@ file exists and nonzero exit status otherwise." (defun tramp-open-shell (vec shell) "Opens shell SHELL." - (tramp-with-progress-reporter + (with-tramp-progress-reporter vec 5 (format "Opening remote shell `%s'" shell) ;; Find arguments for this shell. (let ((tramp-end-of-output tramp-initial-end-of-output) @@ -3638,7 +3653,7 @@ file exists and nonzero exit status otherwise." (tramp-file-name-method vec) 'tramp-remote-shell))) shell) (setq shell - (with-connection-property vec "remote-shell" + (with-tramp-connection-property vec "remote-shell" ;; CCC: "root" does not exist always, see QNAP 459. ;; Which check could we apply instead? (tramp-send-command vec "echo ~root" t) @@ -3673,7 +3688,7 @@ file exists and nonzero exit status otherwise." (tramp-open-shell vec shell)) ;; Busyboxes tend to behave strange. We check for the existence. - (with-connection-property vec "busybox" + (with-tramp-connection-property vec "busybox" (tramp-send-command vec (format "%s --version" shell) t) (let ((case-fold-search t)) (and (string-match "busybox" (buffer-string)) t)))))) @@ -3798,7 +3813,7 @@ process to set up. VEC specifies the connection." ;; successfully, sending 625 bytes failed. Emacs makes a hack when ;; this host type is detected locally. It cannot handle remote ;; hosts, though. - (with-connection-property proc "chunksize" + (with-tramp-connection-property proc "chunksize" (cond ((and (integerp tramp-chunksize) (> tramp-chunksize 0)) tramp-chunksize) @@ -4327,7 +4342,7 @@ connection if a previous connection has died for some reason." (when (and (boundp 'non-essential) (symbol-value 'non-essential)) (throw 'non-essential 'non-essential)) - (tramp-with-progress-reporter + (with-tramp-progress-reporter vec 3 (if (zerop (length (tramp-file-name-user vec))) (format "Opening connection for %s using %s" @@ -4773,7 +4788,7 @@ This is used internally by `tramp-file-mode-from-int'." ;; Variables local to connection. (defun tramp-get-remote-path (vec) - (with-connection-property + (with-tramp-connection-property ;; When `tramp-own-remote-path' is in `tramp-remote-path', we ;; cache the result for the session only. Otherwise, the result ;; is cached persistently. @@ -4845,7 +4860,7 @@ This is used internally by `tramp-file-mode-from-int'." remote-path))))) (defun tramp-get-ls-command (vec) - (with-connection-property vec "ls" + (with-tramp-connection-property vec "ls" (tramp-message vec 5 "Finding a suitable `ls' command") (or (catch 'ls-found @@ -4871,7 +4886,7 @@ This is used internally by `tramp-file-mode-from-int'." (defun tramp-get-ls-command-with-dired (vec) (save-match-data - (with-connection-property vec "ls-dired" + (with-tramp-connection-property vec "ls-dired" (tramp-message vec 5 "Checking, whether `ls --dired' works") ;; Some "ls" versions are sensible wrt the order of arguments, ;; they fail when "-al" is after the "--dired" argument (for @@ -4880,7 +4895,7 @@ This is used internally by `tramp-file-mode-from-int'." vec (format "%s --dired -al /dev/null" (tramp-get-ls-command vec)))))) (defun tramp-get-test-command (vec) - (with-connection-property vec "test" + (with-tramp-connection-property vec "test" (tramp-message vec 5 "Finding a suitable `test' command") (if (tramp-send-command-and-check vec "test 0") "test" @@ -4890,7 +4905,7 @@ This is used internally by `tramp-file-mode-from-int'." ;; Does `test A -nt B' work? Use abominable `find' construct if it ;; doesn't. BSD/OS 4.0 wants the parentheses around the command, ;; for otherwise the shell crashes. - (with-connection-property vec "test-nt" + (with-tramp-connection-property vec "test-nt" (or (progn (tramp-send-command @@ -4908,17 +4923,17 @@ This is used internally by `tramp-file-mode-from-int'." "tramp_test_nt %s %s")))) (defun tramp-get-file-exists-command (vec) - (with-connection-property vec "file-exists" + (with-tramp-connection-property vec "file-exists" (tramp-message vec 5 "Finding command to check if file exists") (tramp-find-file-exists-command vec))) (defun tramp-get-remote-ln (vec) - (with-connection-property vec "ln" + (with-tramp-connection-property vec "ln" (tramp-message vec 5 "Finding a suitable `ln' command") (tramp-find-executable vec "ln" (tramp-get-remote-path vec)))) (defun tramp-get-remote-perl (vec) - (with-connection-property vec "perl" + (with-tramp-connection-property vec "perl" (tramp-message vec 5 "Finding a suitable `perl' command") (let ((result (or (tramp-find-executable vec "perl5" (tramp-get-remote-path vec)) @@ -4926,16 +4941,16 @@ This is used internally by `tramp-file-mode-from-int'." vec "perl" (tramp-get-remote-path vec))))) ;; We must check also for some Perl modules. (when result - (with-connection-property vec "perl-file-spec" + (with-tramp-connection-property vec "perl-file-spec" (tramp-send-command-and-check vec (format "%s -e 'use File::Spec;'" result))) - (with-connection-property vec "perl-cwd-realpath" + (with-tramp-connection-property vec "perl-cwd-realpath" (tramp-send-command-and-check vec (format "%s -e 'use Cwd \"realpath\";'" result)))) result))) (defun tramp-get-remote-stat (vec) - (with-connection-property vec "stat" + (with-tramp-connection-property vec "stat" (tramp-message vec 5 "Finding a suitable `stat' command") (let ((result (tramp-find-executable vec "stat" (tramp-get-remote-path vec))) @@ -4953,7 +4968,7 @@ This is used internally by `tramp-file-mode-from-int'." result))) (defun tramp-get-remote-readlink (vec) - (with-connection-property vec "readlink" + (with-tramp-connection-property vec "readlink" (tramp-message vec 5 "Finding a suitable `readlink' command") (let ((result (tramp-find-executable vec "readlink" (tramp-get-remote-path vec)))) @@ -4963,12 +4978,12 @@ This is used internally by `tramp-file-mode-from-int'." result)))) (defun tramp-get-remote-trash (vec) - (with-connection-property vec "trash" + (with-tramp-connection-property vec "trash" (tramp-message vec 5 "Finding a suitable `trash' command") (tramp-find-executable vec "trash" (tramp-get-remote-path vec)))) (defun tramp-get-remote-id (vec) - (with-connection-property vec "id" + (with-tramp-connection-property vec "id" (tramp-message vec 5 "Finding POSIX `id' command") (or (catch 'id-found @@ -4982,7 +4997,7 @@ This is used internally by `tramp-file-mode-from-int'." (tramp-error vec 'file-error "Couldn't find a POSIX `id' command")))) (defun tramp-get-remote-uid (vec id-format) - (with-connection-property vec (format "uid-%s" id-format) + (with-tramp-connection-property vec (format "uid-%s" id-format) (let ((res (tramp-send-command-and-read vec (format "%s -u%s %s" @@ -4994,7 +5009,7 @@ This is used internally by `tramp-file-mode-from-int'." (if (and (equal id-format 'integer) (not (integerp res))) -1 res)))) (defun tramp-get-remote-gid (vec id-format) - (with-connection-property vec (format "gid-%s" id-format) + (with-tramp-connection-property vec (format "gid-%s" id-format) (let ((res (tramp-send-command-and-read vec (format "%s -g%s %s" @@ -5009,7 +5024,9 @@ This is used internally by `tramp-file-mode-from-int'." (if (equal id-format 'integer) (user-uid) (user-login-name))) (defun tramp-get-local-gid (id-format) - (nth 3 (tramp-compat-file-attributes "~/" id-format))) + (if (and (fboundp 'group-gid) (equal id-format 'integer)) + (tramp-compat-funcall 'group-gid) + (nth 3 (tramp-compat-file-attributes "~/" id-format)))) ;; Some predefined connection properties. (defun tramp-get-inline-compress (vec prop size) @@ -5020,7 +5037,7 @@ the length of the file to be compressed. If no corresponding command is found, nil is returned." (when (and (integerp tramp-inline-compress-start-size) (> size tramp-inline-compress-start-size)) - (with-connection-property (tramp-get-connection-process vec) prop + (with-tramp-connection-property (tramp-get-connection-process vec) prop (tramp-find-inline-compress vec) (tramp-get-connection-property (tramp-get-connection-process vec) prop nil)))) @@ -5041,7 +5058,8 @@ function cell is returned to be applied on a buffer." ;; no inline coding is found. (ignore-errors (let ((coding - (with-connection-property (tramp-get-connection-process vec) prop + (with-tramp-connection-property + (tramp-get-connection-process vec) prop (tramp-find-inline-encoding vec) (tramp-get-connection-property (tramp-get-connection-process vec) prop nil))) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index f1d54b6fd3c..d4386a5374c 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -265,6 +265,8 @@ This can be used to disable echo etc." :type 'string :version "24.3") +;; It must be a `defsubst' in order to push the whole code into +;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading. ;;;###tramp-autoload (defsubst tramp-smb-file-name-p (filename) "Check if it's a filename for SMB servers." @@ -355,7 +357,7 @@ pass to the OPERATION." (let ((t1 (tramp-tramp-file-p dirname)) (t2 (tramp-tramp-file-p newname))) (with-parsed-tramp-file-name (if t1 dirname newname) nil - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 0 (format "Copying %s to %s" dirname newname) (cond ;; We must use a local temporary directory. @@ -491,7 +493,7 @@ KEEP-DATE has no effect in case NEWNAME resides on an SMB server. PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored." (setq filename (expand-file-name filename) newname (expand-file-name newname)) - (tramp-with-progress-reporter + (with-tramp-progress-reporter (tramp-dissect-file-name (if (file-remote-p filename) filename newname)) 0 (format "Copying %s to %s" filename newname) @@ -642,7 +644,8 @@ PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored." (unless id-format (setq id-format 'integer)) (ignore-errors (with-parsed-tramp-file-name filename nil - (with-file-property v localname (format "file-attributes-%s" id-format) + (with-tramp-file-property + v localname (format "file-attributes-%s" id-format) (if (and (tramp-smb-get-share v) (tramp-smb-get-stat-capability v)) (tramp-smb-do-file-attributes-with-stat v id-format) ;; Reading just the filename entry via "dir localname" is not @@ -753,7 +756,7 @@ PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored." v 'file-error "Cannot make local copy of non-existing file `%s'" filename)) (let ((tmpfile (tramp-compat-make-temp-file filename))) - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Fetching %s to tmp file %s" filename tmpfile) (unless (tramp-smb-send-command v (format "get \"%s\" \"%s\"" @@ -771,7 +774,7 @@ PRESERVE-UID-GID and PRESERVE-SELINUX-CONTEXT are completely ignored." (all-completions filename (with-parsed-tramp-file-name directory nil - (with-file-property v localname "file-name-all-completions" + (with-tramp-file-property v localname "file-name-all-completions" (save-match-data (let ((entries (tramp-smb-get-file-entries directory))) (mapcar @@ -1119,7 +1122,7 @@ target of the symlink differ." (if (file-remote-p filename) filename newname)) 'file-already-exists newname)) - (tramp-with-progress-reporter + (with-tramp-progress-reporter (tramp-dissect-file-name (if (file-remote-p filename) filename newname)) 0 (format "Renaming %s to %s" filename newname) @@ -1253,7 +1256,7 @@ errors for shares like \"C$/\", which are common in Microsoft Windows." (list start end tmpfile append 'no-message lockname confirm) (list start end tmpfile append 'no-message lockname))) - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Moving tmp file %s to %s" tmpfile filename) (unwind-protect (unless (tramp-smb-send-command @@ -1312,7 +1315,7 @@ Either the shares are listed, or the `dir' command is executed. Result is a list of (LOCALNAME MODE SIZE MONTH DAY TIME YEAR)." (with-parsed-tramp-file-name (file-name-as-directory directory) nil (setq localname (or localname "/")) - (with-file-property v localname "file-entries" + (with-tramp-file-property v localname "file-entries" (with-current-buffer (tramp-get-connection-buffer v) (let* ((share (tramp-smb-get-share v)) (cache (tramp-get-connection-property v "share-cache" nil)) @@ -1497,7 +1500,7 @@ Result is the list (LOCALNAME MODE SIZE MTIME)." ;; When we are not logged in yet, we return nil. (if (let ((p (tramp-get-connection-process vec))) (and p (processp p) (memq (process-status p) '(run open)))) - (with-connection-property + (with-tramp-connection-property (tramp-get-connection-process vec) "cifs-capabilities" (save-match-data (when (tramp-smb-send-command vec "posix") @@ -1515,7 +1518,7 @@ Result is the list (LOCALNAME MODE SIZE MTIME)." ;; When we are not logged in yet, we return nil. (if (let ((p (tramp-get-connection-process vec))) (and p (processp p) (memq (process-status p) '(run open)))) - (with-connection-property + (with-tramp-connection-property (tramp-get-connection-process vec) "stat-capability" (tramp-smb-send-command vec "stat .")))) @@ -1625,7 +1628,7 @@ If ARGUMENT is non-nil, use it as argument for (setq args (append args (list argument)))) ;; OK, let's go. - (tramp-with-progress-reporter + (with-tramp-progress-reporter vec 3 (format "Opening connection for //%s%s/%s" (if (not (zerop (length user))) (concat user "@") "") @@ -1676,11 +1679,11 @@ If ARGUMENT is non-nil, use it as argument for (tramp-set-connection-property vec "smbserver-version" smbserver-version)))) - ;; Set chunksize. Otherwise, `tramp-send-string' might - ;; try it itself. + ;; Set chunksize to 1. smbclient reads its input + ;; character by character; if we send the string + ;; at once, it is read painfully slow. (tramp-set-connection-property p "smb-share" share) - (tramp-set-connection-property - p "chunksize" tramp-chunksize)) + (tramp-set-connection-property p "chunksize" 1)) ;; Check for the error reason. If it was due to wrong ;; password, reestablish the connection. We cannot @@ -1716,7 +1719,7 @@ Returns nil if an error message has appeared." (while (and (not found) (not err) (memq (process-status p) '(run open))) ;; Accept pending output. - (tramp-accept-process-output p) + (tramp-accept-process-output p 0.1) ;; Search for prompt. (goto-char (point-min)) @@ -1730,7 +1733,7 @@ Returns nil if an error message has appeared." (while (and (not found) (memq (process-status p) '(run open))) ;; Accept pending output. - (tramp-accept-process-output p) + (tramp-accept-process-output p 0.1) ;; Search for prompt. (goto-char (point-min)) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index a17bbfa0d14..a4d36cbe72c 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -403,6 +403,7 @@ interpreted as a regular expression which always matches." (defcustom tramp-save-ad-hoc-proxies nil "Whether to save ad-hoc proxies persistently." :group 'tramp + :version "24.3" :type 'boolean) (defcustom tramp-restricted-shell-hosts-alist @@ -1352,8 +1353,7 @@ ARGS to actually emit the message (if applicable)." "tramp-debug-message" "tramp-error" "tramp-error-with-buffer" - "tramp-message" - "tramp-with-progress-reporter") + "tramp-message") t) "$") fn))) @@ -1497,7 +1497,7 @@ If VAR is nil, then we bind `v' to the structure and `method', `user', (when (string-match message (or (current-message) "")) (tramp-compat-funcall 'progress-reporter-update reporter value)))) -(defmacro tramp-with-progress-reporter (vec level message &rest body) +(defmacro with-tramp-progress-reporter (vec level message &rest body) "Executes BODY, spinning a progress reporter with MESSAGE. If LEVEL does not fit for visible messages, or if this is a nested call of the macro, there are only traces without a visible @@ -1526,7 +1526,42 @@ progress reporter." (tramp-message ,vec ,level "%s...done" ,message)))) (tramp-compat-font-lock-add-keywords - 'emacs-lisp-mode '("\\<tramp-with-progress-reporter\\>")) + 'emacs-lisp-mode '("\\<with-tramp-progress-reporter\\>")) + +(defmacro with-tramp-file-property (vec file property &rest body) + "Check in Tramp cache for PROPERTY, otherwise execute BODY and set cache. +FILE must be a local file name on a connection identified via VEC." + `(if (file-name-absolute-p ,file) + (let ((value (tramp-get-file-property ,vec ,file ,property 'undef))) + (when (eq value 'undef) + ;; We cannot pass @body as parameter to + ;; `tramp-set-file-property' because it mangles our + ;; debug messages. + (setq value (progn ,@body)) + (tramp-set-file-property ,vec ,file ,property value)) + value) + ,@body)) + +(put 'with-tramp-file-property 'lisp-indent-function 3) +(put 'with-tramp-file-property 'edebug-form-spec t) +(tramp-compat-font-lock-add-keywords + 'emacs-lisp-mode '("\\<with-tramp-file-property\\>")) + +(defmacro with-tramp-connection-property (key property &rest body) + "Check in Tramp for property PROPERTY, otherwise executes BODY and set." + `(let ((value (tramp-get-connection-property ,key ,property 'undef))) + (when (eq value 'undef) + ;; We cannot pass ,@body as parameter to + ;; `tramp-set-connection-property' because it mangles our debug + ;; messages. + (setq value (progn ,@body)) + (tramp-set-connection-property ,key ,property value)) + value)) + +(put 'with-tramp-connection-property 'lisp-indent-function 2) +(put 'with-tramp-connection-property 'edebug-form-spec t) +(tramp-compat-font-lock-add-keywords + 'emacs-lisp-mode '("\\<with-tramp-connection-property\\>")) (defalias 'tramp-drop-volume-letter (if (memq system-type '(cygwin windows-nt)) @@ -1713,20 +1748,28 @@ value of `default-file-modes', without execute permissions." (or (file-modes filename) (logand (default-file-modes) (tramp-compat-octal-to-decimal "0666")))) -(defun tramp-replace-environment-variables (filename) - "Replace environment variables in FILENAME. +(defalias 'tramp-replace-environment-variables + (if (ignore-errors + (equal "${ tramp?}" + (tramp-compat-funcall + 'substitute-env-vars "${ tramp?}" 'only-defined))) + (lambda (filename) + "Like `substitute-env-vars' with `only-defined' non-nil." + (tramp-compat-funcall 'substitute-env-vars filename 'only-defined)) + (lambda (filename) + "Replace environment variables in FILENAME. Return the string with the replaced variables." - (save-match-data - (let ((idx (string-match "$\\(\\w+\\)" filename))) - ;; `$' is coded as `$$'. - (when (and idx - (or (zerop idx) (not (eq ?$ (aref filename (1- idx))))) - (getenv (match-string 1 filename))) - (setq filename - (replace-match - (substitute-in-file-name (match-string 0 filename)) - t nil filename))) - filename))) + (save-match-data + (let ((idx (string-match "$\\(\\w+\\)" filename))) + ;; `$' is coded as `$$'. + (when (and idx + (or (zerop idx) (not (eq ?$ (aref filename (1- idx))))) + (getenv (match-string 1 filename))) + (setq filename + (replace-match + (substitute-in-file-name (match-string 0 filename)) + t nil filename))) + filename))))) ;; In XEmacs, electricity is implemented via a key map for ?/ and ?~, ;; which calls corresponding functions (see minibuf.el). @@ -1887,10 +1930,7 @@ ARGS are the arguments OPERATION has been called with." ;; Emacs 23+ only. 'start-file-process ;; XEmacs only. - 'dired-print-file 'dired-shell-call-process - ;; nowhere yet. - 'executable-find 'start-process - 'call-process 'call-process-region)) + 'dired-print-file 'dired-shell-call-process)) default-directory) ;; Unknown file primitive. (t (error "unknown file I/O primitive: %s" operation)))) @@ -2859,7 +2899,7 @@ User is always nil." (setq filename (expand-file-name filename)) (let (result local-copy remote-copy) (with-parsed-tramp-file-name filename nil - (tramp-with-progress-reporter + (with-tramp-progress-reporter v 3 (format "Inserting `%s'" filename) (unwind-protect (if (not (file-exists-p filename)) @@ -2982,7 +3022,7 @@ User is always nil." (if (not (file-exists-p file)) nil (let ((tramp-message-show-message (not nomessage))) - (tramp-with-progress-reporter v 0 (format "Loading %s" file) + (with-tramp-progress-reporter v 0 (format "Loading %s" file) (let ((local-copy (file-local-copy file))) ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil. (unwind-protect @@ -3126,7 +3166,7 @@ beginning of local filename are not substituted." "Send the login name." (when (not (stringp tramp-current-user)) (setq tramp-current-user - (with-connection-property vec "login-as" + (with-tramp-connection-property vec "login-as" (save-window-excursion (let ((enable-recursive-minibuffers t)) (pop-to-buffer (tramp-get-connection-buffer vec)) @@ -3293,7 +3333,9 @@ for process communication also." ;; Under Windows XP, accept-process-output doesn't return ;; sometimes. So we add an additional timeout. (with-timeout ((or timeout 1)) - (accept-process-output proc timeout timeout-msecs (and proc t)))) + (if (featurep 'xemacs) + (accept-process-output proc timeout timeout-msecs) + (accept-process-output proc timeout timeout-msecs (and proc t))))) (tramp-message proc 10 "\n%s" (buffer-string)))) (defun tramp-check-for-regexp (proc regexp) @@ -3414,13 +3456,13 @@ the remote host use line-endings as defined in the variable (defun tramp-get-inode (vec) "Returns the virtual inode number. If it doesn't exist, generate a new one." - (with-file-property vec (tramp-file-name-localname vec) "inode" + (with-tramp-file-property vec (tramp-file-name-localname vec) "inode" (setq tramp-inodes (1+ tramp-inodes)))) (defun tramp-get-device (vec) "Returns the virtual device number. If it doesn't exist, generate a new one." - (with-connection-property (tramp-get-connection-process vec) "device" + (with-tramp-connection-property (tramp-get-connection-process vec) "device" (cons -1 (setq tramp-devices (1+ tramp-devices))))) (defun tramp-equal-remote (file1 file2) @@ -3542,7 +3584,7 @@ would yield `t'. On the other hand, the following check results in nil: (defun tramp-get-remote-tmpdir (vec) "Return directory for temporary files on the remote host identified by VEC." - (with-connection-property vec "tmpdir" + (with-tramp-connection-property vec "tmpdir" (let ((dir (tramp-make-tramp-file-name (tramp-file-name-method vec) (tramp-file-name-user vec) @@ -3724,6 +3766,7 @@ Invokes `password-read' if available, `read-passwd' else." ("oct" . 10) ("nov" . 11) ("dec" . 12)) "Alist mapping month names to integers.") +;; FIXME: Shouldn't this also look at any subseconds parts of T1 and T2? ;;;###tramp-autoload (defun tramp-time-less-p (t1 t2) "Say whether time value T1 is less than time value T2." @@ -3733,6 +3776,7 @@ Invokes `password-read' if available, `read-passwd' else." (and (= (car t1) (car t2)) (< (nth 1 t1) (nth 1 t2))))) +;; FIXME: Shouldn't this also look at any subseconds parts of T1 and T2? (defun tramp-time-subtract (t1 t2) "Subtract two time values. Return the difference in the format of a time value." @@ -3830,7 +3874,6 @@ Only works for Bourne-like shells." ;; * In Emacs 21, `insert-directory' shows total number of bytes used ;; by the files in that directory. Add this here. ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman) -;; * Make ffap.el grok Tramp filenames. (Eli Tziperman) ;; * abbreviate-file-name ;; * Better error checking. At least whenever we see something ;; strange when doing zerop, we should kill the process and start diff --git a/lisp/net/trampver.el b/lisp/net/trampver.el index 499af730788..331884691f4 100644 --- a/lisp/net/trampver.el +++ b/lisp/net/trampver.el @@ -31,7 +31,7 @@ ;; should be changed only there. ;;;###tramp-autoload -(defconst tramp-version "2.2.6-pre" +(defconst tramp-version "2.2.7-pre" "This version of Tramp.") ;;;###tramp-autoload @@ -44,7 +44,7 @@ (= emacs-major-version 21) (>= emacs-minor-version 4))) "ok" - (format "Tramp 2.2.6-pre is not fit for %s" + (format "Tramp 2.2.7-pre is not fit for %s" (when (string-match "^.*$" (emacs-version)) (match-string 0 (emacs-version))))))) (unless (string-match "\\`ok\\'" x) (error "%s" x))) diff --git a/lisp/net/webjump.el b/lisp/net/webjump.el index 232e5ca581a..d5de2f410c5 100644 --- a/lisp/net/webjump.el +++ b/lisp/net/webjump.el @@ -38,7 +38,7 @@ ;; example sites. You'll probably want to override it with your own favorite ;; sites. The documentation for the variable describes the syntax. -;; You may wish to add something like the following to your `.emacs' file: +;; You may wish to add something like the following to your init file: ;; ;; (require 'webjump) ;; (global-set-key "\C-cj" 'webjump) |
