1 ;;; tramp-gvfs.el --- Tramp access functions for GVFS daemon
3 ;; Copyright (C) 2009-2016 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Access functions for the GVFS daemon from Tramp. Tested with GVFS
27 ;; 1.0 (Ubuntu 8.10, Gnome 2.24). It has been reported also to run
28 ;; with GVFS 0.2.5 (Ubuntu 8.04, Gnome 2.22), but there is an
29 ;; incompatibility with the mount_info structure, which has been
32 ;; It has also been tested with GVFS 1.6 (Ubuntu 10.04, Gnome 2.30),
33 ;; where the default_location has been added to mount_info (see
34 ;; <https://bugzilla.gnome.org/show_bug.cgi?id=561998>.
36 ;; With GVFS 1.14 (Ubuntu 12.10, Gnome 3.6) the interfaces have been
37 ;; changed, again. So we must introspect the D-Bus interfaces.
39 ;; All actions to mount a remote location, and to retrieve mount
40 ;; information, are performed by D-Bus messages. File operations
41 ;; themselves are performed via the mounted filesystem in ~/.gvfs.
42 ;; Consequently, GNU Emacs 23.1 with enabled D-Bus bindings is a
45 ;; The GVFS D-Bus interface is said to be unstable. There were even
46 ;; no introspection data before GVFS 1.14. The interface, as
47 ;; discovered during development time, is given in respective
50 ;; The custom option `tramp-gvfs-methods' contains the list of
51 ;; supported connection methods. Per default, these are "afp", "dav",
52 ;; "davs", "gdrive", "obex", "sftp" and "synce". Note that with
53 ;; "obex" it might be necessary to pair with the other bluetooth
54 ;; device, if it hasn't been done already. There might be also some
55 ;; few seconds delay in discovering available bluetooth devices.
57 ;; Other possible connection methods are "ftp" and "smb". When one of
58 ;; these methods is added to the list, the remote access for that
59 ;; method is performed via GVFS instead of the native Tramp
62 ;; GVFS offers even more connection methods. The complete list of
63 ;; connection methods of the actual GVFS implementation can be
71 ;; :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
72 ;; tramp-gvfs-interface-mounttracker "listMountableInfo")))
74 ;; Note that all other connection methods are not tested, beside the
75 ;; ones offered for customization in `tramp-gvfs-methods'. If you
76 ;; request an additional connection method to be supported, please
79 ;; For hostname completion, information is retrieved either from the
80 ;; bluez daemon (for the "obex" method), the hal daemon (for the
81 ;; "synce" method), or from the zeroconf daemon (for the "afp", "dav",
82 ;; "davs", and "sftp" methods). The zeroconf daemon is pre-configured
83 ;; to discover services in the "local" domain. If another domain
84 ;; shall be used for discovering services, the custom option
85 ;; `tramp-gvfs-zeroconf-domain' can be set accordingly.
89 ;; * The current GVFS implementation does not allow writing on the
90 ;; remote bluetooth device via OBEX.
92 ;; * Two shares of the same SMB server cannot be mounted in parallel.
96 ;; D-Bus support in the Emacs core can be disabled with configuration
97 ;; option "--without-dbus". Declare used subroutines and variables.
98 (declare-function dbus-get-unique-name
"dbusbind.c")
107 ;; Pacify byte-compiler.
113 (defcustom tramp-gvfs-methods
114 '("afp" "dav" "davs" "gdrive" "obex" "sftp" "synce")
115 "List of methods for remote files, accessed with GVFS."
118 :type
'(repeat (choice (const "afp")
129 ;; Add defaults for `tramp-default-user-alist' and `tramp-default-host-alist'.
131 (when (string-match "\\(.+\\)@\\(\\(?:gmail\\|googlemail\\)\\.com\\)"
133 (add-to-list 'tramp-default-user-alist
134 `("\\`gdrive\\'" nil
,(match-string 1 user-mail-address
)))
135 (add-to-list 'tramp-default-host-alist
136 '("\\`gdrive\\'" nil
,(match-string 2 user-mail-address
))))
138 (add-to-list 'tramp-default-user-alist
'("\\`synce\\'" nil nil
))
141 (defcustom tramp-gvfs-zeroconf-domain
"local"
142 "Zeroconf domain to be used for discovering services, like host names."
148 ;; Add the methods to `tramp-methods', in order to allow minibuffer
151 (when (featurep 'dbusbind
)
152 (dolist (elt tramp-gvfs-methods
)
153 (unless (assoc elt tramp-methods
)
154 (add-to-list 'tramp-methods
(cons elt nil
)))))
156 (defconst tramp-gvfs-path-tramp
(concat dbus-path-emacs
"/Tramp")
157 "The preceding object path for own objects.")
159 (defconst tramp-gvfs-service-daemon
"org.gtk.vfs.Daemon"
160 "The well known name of the GVFS daemon.")
162 ;; D-Bus integration is available since Emacs 23 on some system types.
163 ;; We don't call `dbus-ping', because this would load dbus.el.
164 (defconst tramp-gvfs-enabled
166 (and (featurep 'dbusbind
)
167 (tramp-compat-funcall 'dbus-get-unique-name
:system
)
168 (tramp-compat-funcall 'dbus-get-unique-name
:session
)
169 (or (tramp-compat-process-running-p "gvfs-fuse-daemon")
170 (tramp-compat-process-running-p "gvfsd-fuse"))))
171 "Non-nil when GVFS is available.")
173 (defconst tramp-gvfs-path-mounttracker
"/org/gtk/vfs/mounttracker"
174 "The object path of the GVFS daemon.")
176 (defconst tramp-gvfs-interface-mounttracker
"org.gtk.vfs.MountTracker"
177 "The mount tracking interface in the GVFS daemon.")
179 ;; Introspection data exist since GVFS 1.14. If there are no such
180 ;; data, we expect an earlier interface.
181 (defconst tramp-gvfs-methods-mounttracker
182 (and tramp-gvfs-enabled
183 (dbus-introspect-get-method-names
184 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
185 tramp-gvfs-interface-mounttracker
))
186 "The list of supported methods of the mount tracking interface.")
188 (defconst tramp-gvfs-listmounts
189 (if (member "ListMounts" tramp-gvfs-methods-mounttracker
)
192 "The name of the \"listMounts\" method.
193 It has been changed in GVFS 1.14.")
195 (defconst tramp-gvfs-mountlocation
196 (if (member "MountLocation" tramp-gvfs-methods-mounttracker
)
199 "The name of the \"mountLocation\" method.
200 It has been changed in GVFS 1.14.")
202 (defconst tramp-gvfs-mountlocation-signature
203 (and tramp-gvfs-enabled
204 (dbus-introspect-get-signature
205 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
206 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
))
207 "The D-Bus signature of the \"mountLocation\" method.
208 It has been changed in GVFS 1.14.")
210 ;; <interface name='org.gtk.vfs.MountTracker'>
211 ;; <method name='listMounts'>
212 ;; <arg name='mount_info_list'
213 ;; type='a{sosssssbay{aya{say}}ay}'
216 ;; <method name='mountLocation'>
217 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
218 ;; <arg name='dbus_id' type='s' direction='in'/>
219 ;; <arg name='object_path' type='o' direction='in'/>
221 ;; <signal name='mounted'>
222 ;; <arg name='mount_info'
223 ;; type='{sosssssbay{aya{say}}ay}'/>
225 ;; <signal name='unmounted'>
226 ;; <arg name='mount_info'
227 ;; type='{sosssssbay{aya{say}}ay}'/>
233 ;; OBJECT_PATH object_path
234 ;; STRING display_name
235 ;; STRING stable_name
236 ;; STRING x_content_types Since GVFS 1.0 only !!!
238 ;; STRING preferred_filename_encoding
239 ;; BOOLEAN user_visible
240 ;; ARRAY BYTE fuse_mountpoint
242 ;; ARRAY BYTE mount_prefix
244 ;; STRUCT mount_spec_item
245 ;; STRING key (type, user, domain, host, server,
246 ;; share, volume, port, ssl)
248 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
250 (defconst tramp-gvfs-interface-mountoperation
"org.gtk.vfs.MountOperation"
251 "Used by the dbus-proxying implementation of GMountOperation.")
253 ;; <interface name='org.gtk.vfs.MountOperation'>
254 ;; <method name='askPassword'>
255 ;; <arg name='message' type='s' direction='in'/>
256 ;; <arg name='default_user' type='s' direction='in'/>
257 ;; <arg name='default_domain' type='s' direction='in'/>
258 ;; <arg name='flags' type='u' direction='in'/>
259 ;; <arg name='handled' type='b' direction='out'/>
260 ;; <arg name='aborted' type='b' direction='out'/>
261 ;; <arg name='password' type='s' direction='out'/>
262 ;; <arg name='username' type='s' direction='out'/>
263 ;; <arg name='domain' type='s' direction='out'/>
264 ;; <arg name='anonymous' type='b' direction='out'/>
265 ;; <arg name='password_save' type='u' direction='out'/>
267 ;; <method name='askQuestion'>
268 ;; <arg name='message' type='s' direction='in'/>
269 ;; <arg name='choices' type='as' direction='in'/>
270 ;; <arg name='handled' type='b' direction='out'/>
271 ;; <arg name='aborted' type='b' direction='out'/>
272 ;; <arg name='choice' type='u' direction='out'/>
276 ;; The following flags are used in "askPassword". They are defined in
277 ;; /usr/include/glib-2.0/gio/gioenums.h.
279 (defconst tramp-gvfs-password-need-password
1
280 "Operation requires a password.")
282 (defconst tramp-gvfs-password-need-username
2
283 "Operation requires a username.")
285 (defconst tramp-gvfs-password-need-domain
4
286 "Operation requires a domain.")
288 (defconst tramp-gvfs-password-saving-supported
8
289 "Operation supports saving settings.")
291 (defconst tramp-gvfs-password-anonymous-supported
16
292 "Operation supports anonymous users.")
294 (defconst tramp-bluez-service
"org.bluez"
295 "The well known name of the BLUEZ service.")
297 (defconst tramp-bluez-interface-manager
"org.bluez.Manager"
298 "The manager interface of the BLUEZ daemon.")
300 ;; <interface name='org.bluez.Manager'>
301 ;; <method name='DefaultAdapter'>
302 ;; <arg type='o' direction='out'/>
304 ;; <method name='FindAdapter'>
305 ;; <arg type='s' direction='in'/>
306 ;; <arg type='o' direction='out'/>
308 ;; <method name='ListAdapters'>
309 ;; <arg type='ao' direction='out'/>
311 ;; <signal name='AdapterAdded'>
314 ;; <signal name='AdapterRemoved'>
317 ;; <signal name='DefaultAdapterChanged'>
322 (defconst tramp-bluez-interface-adapter
"org.bluez.Adapter"
323 "The adapter interface of the BLUEZ daemon.")
325 ;; <interface name='org.bluez.Adapter'>
326 ;; <method name='GetProperties'>
327 ;; <arg type='a{sv}' direction='out'/>
329 ;; <method name='SetProperty'>
330 ;; <arg type='s' direction='in'/>
331 ;; <arg type='v' direction='in'/>
333 ;; <method name='RequestMode'>
334 ;; <arg type='s' direction='in'/>
336 ;; <method name='ReleaseMode'/>
337 ;; <method name='RequestSession'/>
338 ;; <method name='ReleaseSession'/>
339 ;; <method name='StartDiscovery'/>
340 ;; <method name='StopDiscovery'/>
341 ;; <method name='ListDevices'>
342 ;; <arg type='ao' direction='out'/>
344 ;; <method name='CreateDevice'>
345 ;; <arg type='s' direction='in'/>
346 ;; <arg type='o' direction='out'/>
348 ;; <method name='CreatePairedDevice'>
349 ;; <arg type='s' direction='in'/>
350 ;; <arg type='o' direction='in'/>
351 ;; <arg type='s' direction='in'/>
352 ;; <arg type='o' direction='out'/>
354 ;; <method name='CancelDeviceCreation'>
355 ;; <arg type='s' direction='in'/>
357 ;; <method name='RemoveDevice'>
358 ;; <arg type='o' direction='in'/>
360 ;; <method name='FindDevice'>
361 ;; <arg type='s' direction='in'/>
362 ;; <arg type='o' direction='out'/>
364 ;; <method name='RegisterAgent'>
365 ;; <arg type='o' direction='in'/>
366 ;; <arg type='s' direction='in'/>
368 ;; <method name='UnregisterAgent'>
369 ;; <arg type='o' direction='in'/>
371 ;; <signal name='DeviceCreated'>
374 ;; <signal name='DeviceRemoved'>
377 ;; <signal name='DeviceFound'>
379 ;; <arg type='a{sv}'/>
381 ;; <signal name='PropertyChanged'>
385 ;; <signal name='DeviceDisappeared'>
391 (defcustom tramp-bluez-discover-devices-timeout
60
392 "Defines seconds since last bluetooth device discovery before rescanning.
393 A value of 0 would require an immediate discovery during hostname
394 completion, nil means to use always cached values for discovered
398 :type
'(choice (const nil
) integer
)
401 (defvar tramp-bluez-discovery nil
402 "Indicator for a running bluetooth device discovery.
403 It keeps the timestamp of last discovery.")
405 (defvar tramp-bluez-devices nil
406 "Alist of detected bluetooth devices.
407 Every entry is a list (NAME ADDRESS).")
409 (defconst tramp-hal-service
"org.freedesktop.Hal"
410 "The well known name of the HAL service.")
412 (defconst tramp-hal-path-manager
"/org/freedesktop/Hal/Manager"
413 "The object path of the HAL daemon manager.")
415 (defconst tramp-hal-interface-manager
"org.freedesktop.Hal.Manager"
416 "The manager interface of the HAL daemon.")
418 (defconst tramp-hal-interface-device
"org.freedesktop.Hal.Device"
419 "The device interface of the HAL daemon.")
421 (defconst tramp-gvfs-file-attributes
424 "standard::display-name"
425 "standard::symlink-target"
438 "access::can-execute"
441 "GVFS file attributes.")
443 (defconst tramp-gvfs-file-attributes-with-gvfs-ls-regexp
444 (concat "[[:blank:]]" (regexp-opt tramp-gvfs-file-attributes t
) "=\\(.+?\\)")
445 "Regexp to parse GVFS file attributes with `gvfs-ls'.")
447 (defconst tramp-gvfs-file-attributes-with-gvfs-info-regexp
448 (concat "^[[:blank:]]*"
449 (regexp-opt tramp-gvfs-file-attributes t
)
450 ":[[:blank:]]+\\(.*\\)$")
451 "Regexp to parse GVFS file attributes with `gvfs-info'.")
454 ;; New handlers should be added here.
455 (defconst tramp-gvfs-file-name-handler-alist
456 '((access-file . ignore
)
457 (add-name-to-file . tramp-gvfs-handle-copy-file
)
458 ;; `byte-compiler-base-file-name' performed by default handler.
459 ;; `copy-directory' performed by default handler.
460 (copy-file . tramp-gvfs-handle-copy-file
)
461 (delete-directory . tramp-gvfs-handle-delete-directory
)
462 (delete-file . tramp-gvfs-handle-delete-file
)
463 ;; `diff-latest-backup-file' performed by default handler.
464 (directory-file-name . tramp-handle-directory-file-name
)
465 (directory-files . tramp-handle-directory-files
)
466 (directory-files-and-attributes
467 . tramp-handle-directory-files-and-attributes
)
468 (dired-compress-file . ignore
)
469 (dired-uncache . tramp-handle-dired-uncache
)
470 (expand-file-name . tramp-gvfs-handle-expand-file-name
)
471 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p
)
473 (file-attributes . tramp-gvfs-handle-file-attributes
)
474 (file-directory-p . tramp-gvfs-handle-file-directory-p
)
475 (file-equal-p . tramp-handle-file-equal-p
)
476 (file-executable-p . tramp-gvfs-handle-file-executable-p
)
477 (file-exists-p . tramp-handle-file-exists-p
)
478 (file-in-directory-p . tramp-handle-file-in-directory-p
)
479 (file-local-copy . tramp-gvfs-handle-file-local-copy
)
480 (file-modes . tramp-handle-file-modes
)
481 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions
)
482 (file-name-as-directory . tramp-handle-file-name-as-directory
)
483 (file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p
)
484 (file-name-completion . tramp-handle-file-name-completion
)
485 (file-name-directory . tramp-handle-file-name-directory
)
486 (file-name-nondirectory . tramp-handle-file-name-nondirectory
)
487 ;; `file-name-sans-versions' performed by default handler.
488 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p
)
489 (file-notify-add-watch . tramp-gvfs-handle-file-notify-add-watch
)
490 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch
)
491 (file-notify-valid-p . tramp-handle-file-notify-valid-p
)
492 (file-ownership-preserved-p . ignore
)
493 (file-readable-p . tramp-gvfs-handle-file-readable-p
)
494 (file-regular-p . tramp-handle-file-regular-p
)
495 (file-remote-p . tramp-handle-file-remote-p
)
496 (file-selinux-context . ignore
)
497 (file-symlink-p . tramp-handle-file-symlink-p
)
498 ;; `file-truename' performed by default handler.
499 (file-writable-p . tramp-gvfs-handle-file-writable-p
)
500 (find-backup-file-name . tramp-handle-find-backup-file-name
)
501 ;; `find-file-noselect' performed by default handler.
502 ;; `get-file-buffer' performed by default handler.
503 (insert-directory . tramp-handle-insert-directory
)
504 (insert-file-contents . tramp-handle-insert-file-contents
)
505 (load . tramp-handle-load
)
506 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name
)
507 (make-directory . tramp-gvfs-handle-make-directory
)
508 (make-directory-internal . ignore
)
509 (make-nearby-temp-file . tramp-handle-make-nearby-temp-file
)
510 (make-symbolic-link . tramp-handle-make-symbolic-link
)
511 (process-file . ignore
)
512 (rename-file . tramp-gvfs-handle-rename-file
)
513 (set-file-acl . ignore
)
514 (set-file-modes . ignore
)
515 (set-file-selinux-context . ignore
)
516 (set-file-times . ignore
)
517 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime
)
518 (shell-command . ignore
)
519 (start-file-process . ignore
)
520 (substitute-in-file-name . tramp-handle-substitute-in-file-name
)
521 (temporary-file-directory . tramp-handle-temporary-file-directory
)
522 (unhandled-file-name-directory . ignore
)
523 (vc-registered . ignore
)
524 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime
)
525 (write-region . tramp-gvfs-handle-write-region
))
526 "Alist of handler functions for Tramp GVFS method.
527 Operations not mentioned here will be handled by the default Emacs primitives.")
529 ;; It must be a `defsubst' in order to push the whole code into
530 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
532 (defsubst tramp-gvfs-file-name-p
(filename)
533 "Check if it's a filename handled by the GVFS daemon."
534 (and (tramp-tramp-file-p filename
)
536 (tramp-file-name-method (tramp-dissect-file-name filename
))))
537 (and (stringp method
) (member method tramp-gvfs-methods
)))))
540 (defun tramp-gvfs-file-name-handler (operation &rest args
)
541 "Invoke the GVFS related OPERATION.
542 First arg specifies the OPERATION, second arg is a list of arguments to
543 pass to the OPERATION."
544 (unless tramp-gvfs-enabled
545 (tramp-compat-user-error nil
"Package `tramp-gvfs' not supported"))
546 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist
)))
548 (save-match-data (apply (cdr fn
) args
))
549 (tramp-run-real-handler operation args
))))
551 ;; This might be moved to tramp.el. It shall be the first file name
554 (when (featurep 'dbusbind
)
555 (add-to-list 'tramp-foreign-file-name-handler-alist
556 (cons 'tramp-gvfs-file-name-p
'tramp-gvfs-file-name-handler
)))
559 ;; D-Bus helper function.
561 (defun tramp-gvfs-dbus-string-to-byte-array (string)
562 "Like `dbus-string-to-byte-array' but add trailing \\0 if needed."
563 (dbus-string-to-byte-array
564 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature
)
565 (concat string
(string 0)) string
)))
567 (defun tramp-gvfs-dbus-byte-array-to-string (byte-array)
568 "Like `dbus-byte-array-to-string' but remove trailing \\0 if exists."
569 ;; The byte array could be a variant. Take care.
571 (if (and (consp byte-array
) (atom (car byte-array
)))
572 byte-array
(car byte-array
))))
573 (dbus-byte-array-to-string
574 (if (and (consp byte-array
) (zerop (car (last byte-array
))))
575 (butlast byte-array
) byte-array
))))
577 (defun tramp-gvfs-stringify-dbus-message (message)
578 "Convert a D-Bus message into readable UTF8 strings, used for traces."
580 ((and (consp message
) (characterp (car message
)))
581 (format "%S" (tramp-gvfs-dbus-byte-array-to-string message
)))
583 (mapcar 'tramp-gvfs-stringify-dbus-message message
))
585 (format "%S" message
))
588 (defmacro with-tramp-dbus-call-method
589 (vec synchronous bus service path interface method
&rest args
)
590 "Apply a D-Bus call on bus BUS.
592 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
593 it is an asynchronous call, with `ignore' as callback function.
595 The other arguments have the same meaning as with `dbus-call-method'
596 or `dbus-call-method-asynchronously'. Additionally, the call
597 will be traced by Tramp with trace level 6."
598 `(let ((func (if ,synchronous
599 'dbus-call-method
'dbus-call-method-asynchronously
))
600 (args (append (list ,bus
,service
,path
,interface
,method
)
601 (if ,synchronous
(list ,@args
) (list 'ignore
,@args
))))
603 (tramp-message ,vec
6 "%s %s" func args
)
604 (setq result
(apply func args
))
605 (tramp-message ,vec
6 "%s" (tramp-gvfs-stringify-dbus-message result
))
608 (put 'with-tramp-dbus-call-method
'lisp-indent-function
2)
609 (put 'with-tramp-dbus-call-method
'edebug-form-spec
'(form symbolp body
))
610 (font-lock-add-keywords 'emacs-lisp-mode
'("\\<with-tramp-dbus-call-method\\>"))
612 (defvar tramp-gvfs-dbus-event-vector nil
613 "Current Tramp file name to be used, as vector.
614 It is needed when D-Bus signals or errors arrive, because there
615 is no information where to trace the message.")
617 (defun tramp-gvfs-dbus-event-error (event err
)
618 "Called when a D-Bus error message arrives, see `dbus-event-error-functions'."
619 (when tramp-gvfs-dbus-event-vector
620 (tramp-message tramp-gvfs-dbus-event-vector
10 "%S" event
)
621 (tramp-error tramp-gvfs-dbus-event-vector
'file-error
"%s" (cadr err
))))
623 ;; `dbus-event-error-hooks' has been renamed to `dbus-event-error-functions'.
625 (if (boundp 'dbus-event-error-functions
)
626 'dbus-event-error-functions
'dbus-event-error-hooks
)
627 'tramp-gvfs-dbus-event-error
)
630 ;; File name primitives.
632 (defun tramp-gvfs-do-copy-or-rename-file
633 (op filename newname
&optional ok-if-already-exists keep-date
634 preserve-uid-gid preserve-extended-attributes
)
635 "Copy or rename a remote file.
636 OP must be `copy' or `rename' and indicates the operation to perform.
637 FILENAME specifies the file to copy or rename, NEWNAME is the name of
638 the new file (for copy) or the new name of the file (for rename).
639 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
640 KEEP-DATE means to make sure that NEWNAME has the same timestamp
641 as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
642 the uid and gid if both files are on the same host.
643 PRESERVE-EXTENDED-ATTRIBUTES is ignored.
645 This function is invoked by `tramp-gvfs-handle-copy-file' and
646 `tramp-gvfs-handle-rename-file'. It is an error if OP is neither
647 of `copy' and `rename'. FILENAME and NEWNAME must be absolute
649 (unless (memq op
'(copy rename
))
650 (error "Unknown operation `%s', must be `copy' or `rename'" op
))
652 (let ((t1 (tramp-tramp-file-p filename
))
653 (t2 (tramp-tramp-file-p newname
))
654 (equal-remote (tramp-equal-remote filename newname
))
655 (file-operation (intern (format "%s-file" op
)))
656 (gvfs-operation (if (eq op
'copy
) "gvfs-copy" "gvfs-move"))
657 (msg-operation (if (eq op
'copy
) "Copying" "Renaming")))
659 (with-parsed-tramp-file-name (if t1 filename newname
) nil
660 (when (and (not ok-if-already-exists
) (file-exists-p newname
))
662 v
'file-already-exists
"File %s already exists" newname
))
664 (if (or (and equal-remote
665 (tramp-get-connection-property v
"direct-copy-failed" nil
))
666 (and t1
(not (tramp-gvfs-file-name-p filename
)))
667 (and t2
(not (tramp-gvfs-file-name-p newname
))))
669 ;; We cannot copy or rename directly.
670 ;; PRESERVE-EXTENDED-ATTRIBUTES has been introduced with
671 ;; Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and renamed
673 (let ((tmpfile (tramp-compat-make-temp-file filename
)))
675 (preserve-extended-attributes
678 filename tmpfile t keep-date preserve-uid-gid
679 preserve-extended-attributes
))
682 file-operation filename tmpfile t keep-date preserve-uid-gid
)))
683 (rename-file tmpfile newname ok-if-already-exists
))
686 (with-tramp-progress-reporter
687 v
0 (format "%s %s to %s" msg-operation filename newname
)
690 'tramp-gvfs-send-command v gvfs-operation
692 (and (eq op
'copy
) (or keep-date preserve-uid-gid
)
695 (tramp-gvfs-url-file-name filename
)
696 (tramp-gvfs-url-file-name newname
))))
698 (if (or (not equal-remote
)
700 (tramp-get-connection-property
701 v
"direct-copy-failed" nil
)))
702 ;; Propagate the error.
703 (with-current-buffer (tramp-get-connection-buffer v
)
704 (goto-char (point-min))
705 (tramp-error-with-buffer
707 "%s failed, see buffer `%s' for details."
708 msg-operation
(buffer-name)))
710 ;; Some WebDAV server, like the one from QNAP, do not
711 ;; support direct copy/move. Try a fallback.
712 (tramp-set-connection-property v
"direct-copy-failed" t
)
713 (tramp-gvfs-do-copy-or-rename-file
714 op filename newname ok-if-already-exists keep-date
715 preserve-uid-gid preserve-extended-attributes
))))
717 (when (and t1
(eq op
'rename
))
718 (with-parsed-tramp-file-name filename nil
719 (tramp-flush-file-property v
(file-name-directory localname
))
720 (tramp-flush-file-property v localname
)))
723 (with-parsed-tramp-file-name newname nil
724 (tramp-flush-file-property v
(file-name-directory localname
))
725 (tramp-flush-file-property v localname
)))))))
727 (defun tramp-gvfs-handle-copy-file
728 (filename newname
&optional ok-if-already-exists keep-date
729 preserve-uid-gid preserve-extended-attributes
)
730 "Like `copy-file' for Tramp files."
731 (setq filename
(expand-file-name filename
))
732 (setq newname
(expand-file-name newname
))
734 ;; At least one file a Tramp file?
735 ((or (tramp-tramp-file-p filename
)
736 (tramp-tramp-file-p newname
))
737 (tramp-gvfs-do-copy-or-rename-file
738 'copy filename newname ok-if-already-exists keep-date
739 preserve-uid-gid preserve-extended-attributes
))
740 ;; Compat section. PRESERVE-EXTENDED-ATTRIBUTES has been
741 ;; introduced with Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and
742 ;; renamed in Emacs 24.3.
743 (preserve-extended-attributes
744 (tramp-run-real-handler
746 (list filename newname ok-if-already-exists keep-date
747 preserve-uid-gid preserve-extended-attributes
)))
749 (tramp-run-real-handler
751 (list filename newname ok-if-already-exists keep-date preserve-uid-gid
)))))
753 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash
)
754 "Like `delete-directory' for Tramp files."
755 (with-parsed-tramp-file-name directory nil
756 (if (and recursive
(not (file-symlink-p directory
)))
758 (if (eq t
(tramp-compat-file-attribute-type
759 (file-attributes file
)))
760 (tramp-compat-delete-directory file recursive trash
)
761 (tramp-compat-delete-file file trash
)))
763 directory
'full directory-files-no-dot-files-regexp
))
764 (when (directory-files directory nil directory-files-no-dot-files-regexp
)
766 v
'file-error
"Couldn't delete non-empty %s" directory
)))
768 (tramp-flush-file-property v
(file-name-directory localname
))
769 (tramp-flush-directory-property v localname
)
771 (tramp-gvfs-send-command
772 v
(if (and trash delete-by-moving-to-trash
) "gvfs-trash" "gvfs-rm")
773 (tramp-gvfs-url-file-name directory
))
774 ;; Propagate the error.
775 (with-current-buffer (tramp-get-connection-buffer v
)
776 (goto-char (point-min))
777 (tramp-error-with-buffer
778 nil v
'file-error
"Couldn't delete %s" directory
)))))
780 (defun tramp-gvfs-handle-delete-file (filename &optional trash
)
781 "Like `delete-file' for Tramp files."
782 (with-parsed-tramp-file-name filename nil
783 (tramp-flush-file-property v
(file-name-directory localname
))
784 (tramp-flush-file-property v localname
)
786 (tramp-gvfs-send-command
787 v
(if (and trash delete-by-moving-to-trash
) "gvfs-trash" "gvfs-rm")
788 (tramp-gvfs-url-file-name filename
))
789 ;; Propagate the error.
790 (with-current-buffer (tramp-get-connection-buffer v
)
791 (goto-char (point-min))
792 (tramp-error-with-buffer
793 nil v
'file-error
"Couldn't delete %s" filename
)))))
795 (defun tramp-gvfs-handle-expand-file-name (name &optional dir
)
796 "Like `expand-file-name' for Tramp files."
797 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
798 (setq dir
(or dir default-directory
"/"))
799 ;; Unless NAME is absolute, concat DIR and NAME.
800 (unless (file-name-absolute-p name
)
801 (setq name
(concat (file-name-as-directory dir
) name
)))
802 ;; If NAME is not a Tramp file, run the real handler.
803 (if (not (tramp-tramp-file-p name
))
804 (tramp-run-real-handler 'expand-file-name
(list name nil
))
806 (with-parsed-tramp-file-name name nil
807 ;; If there is a default location, expand tilde.
808 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname
)
810 (tramp-gvfs-maybe-open-connection (vector method user host
"/" hop
)))
813 (tramp-get-connection-property v
"default-location" "~")
815 ;; Tilde expansion is not possible.
816 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname
)
819 "Cannot expand tilde in file `%s'" name
))
820 (unless (tramp-run-real-handler 'file-name-absolute-p
(list localname
))
821 (setq localname
(concat "/" localname
)))
822 ;; We do not pass "/..".
823 (if (string-match "^\\(afp\\|smb\\)$" method
)
824 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname
)
825 (setq localname
(replace-match "/" t t localname
1)))
826 (when (string-match "^/\\.\\./?" localname
)
827 (setq localname
(replace-match "/" t t localname
))))
828 ;; There might be a double slash. Remove this.
829 (while (string-match "//" localname
)
830 (setq localname
(replace-match "/" t t localname
)))
831 ;; No tilde characters in file name, do normal
832 ;; `expand-file-name' (this does "/./" and "/../").
833 (tramp-make-tramp-file-name
835 (tramp-run-real-handler
836 'expand-file-name
(list localname
))))))
838 (defun tramp-gvfs-get-directory-attributes (directory)
839 "Return GVFS attributes association list of all files in DIRECTORY."
841 ;; Don't modify `last-coding-system-used' by accident.
842 (let ((last-coding-system-used last-coding-system-used
)
844 (with-parsed-tramp-file-name directory nil
845 (with-tramp-file-property v localname
"directory-gvfs-attributes"
846 (tramp-message v
5 "directory gvfs attributes: %s" localname
)
848 (tramp-gvfs-send-command
849 v
"gvfs-ls" "-h" "-n" "-a"
850 (mapconcat 'identity tramp-gvfs-file-attributes
",")
851 (tramp-gvfs-url-file-name directory
))
853 (with-current-buffer (tramp-get-connection-buffer v
)
854 (goto-char (point-min))
856 (concat "^\\(.+\\)[[:blank:]]"
857 "\\([[:digit:]]+\\)[[:blank:]]"
859 tramp-gvfs-file-attributes-with-gvfs-ls-regexp
))
860 (let ((item (list (cons "type" (match-string 3))
861 (cons "standard::size" (match-string 2))
862 (cons "name" (match-string 1)))))
863 (goto-char (1+ (match-end 3)))
866 tramp-gvfs-file-attributes-with-gvfs-ls-regexp
867 "\\(" tramp-gvfs-file-attributes-with-gvfs-ls-regexp
869 (push (cons (match-string 1) (match-string 2)) item
)
870 (goto-char (match-end 2)))
871 ;; Add display name as head.
873 (cons (cdr (or (assoc "standard::display-name" item
)
874 (assoc "name" item
)))
880 (defun tramp-gvfs-get-root-attributes (filename)
881 "Return GVFS attributes association list of FILENAME."
883 ;; Don't modify `last-coding-system-used' by accident.
884 (let ((last-coding-system-used last-coding-system-used
)
886 (with-parsed-tramp-file-name filename nil
887 (with-tramp-file-property v localname
"file-gvfs-attributes"
888 (tramp-message v
5 "file gvfs attributes: %s" localname
)
890 (tramp-gvfs-send-command
891 v
"gvfs-info" (tramp-gvfs-url-file-name filename
))
893 (with-current-buffer (tramp-get-connection-buffer v
)
894 (goto-char (point-min))
895 (while (re-search-forward
896 tramp-gvfs-file-attributes-with-gvfs-info-regexp nil t
)
897 (push (cons (match-string 1) (match-string 2)) result
))
900 (defun tramp-gvfs-get-file-attributes (filename)
901 "Return GVFS attributes association list of FILENAME."
902 (setq filename
(directory-file-name (expand-file-name filename
)))
903 (with-parsed-tramp-file-name filename nil
905 (and (string-match "^\\(afp\\|smb\\)$" method
)
906 (string-match "^/?\\([^/]+\\)$" localname
))
907 (string-equal localname
"/"))
908 (tramp-gvfs-get-root-attributes filename
)
910 (file-name-nondirectory filename
)
911 (tramp-gvfs-get-directory-attributes (file-name-directory filename
))))))
913 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format
)
914 "Like `file-attributes' for Tramp files."
915 (unless id-format
(setq id-format
'integer
))
917 (let ((attributes (tramp-gvfs-get-file-attributes filename
))
918 dirp res-symlink-target res-numlinks res-uid res-gid res-access
919 res-mod res-change res-size res-filemodes res-inode res-device
)
921 ;; ... directory or symlink
922 (setq dirp
(if (equal "directory" (cdr (assoc "type" attributes
))) t
))
923 (setq res-symlink-target
924 (cdr (assoc "standard::symlink-target" attributes
)))
928 (or (cdr (assoc "unix::nlink" attributes
)) "0")))
931 (if (eq id-format
'integer
)
933 (or (cdr (assoc "unix::uid" attributes
))
934 (format "%s" tramp-unknown-id-integer
)))
935 (or (cdr (assoc "owner::user" attributes
))
936 (cdr (assoc "unix::uid" attributes
))
937 tramp-unknown-id-string
)))
939 (if (eq id-format
'integer
)
941 (or (cdr (assoc "unix::gid" attributes
))
942 (format "%s" tramp-unknown-id-integer
)))
943 (or (cdr (assoc "owner::group" attributes
))
944 (cdr (assoc "unix::gid" attributes
))
945 tramp-unknown-id-string
)))
946 ;; ... last access, modification and change time
950 (or (cdr (assoc "time::access" attributes
)) "0"))))
954 (or (cdr (assoc "time::modified" attributes
)) "0"))))
958 (or (cdr (assoc "time::changed" attributes
)) "0"))))
962 (or (cdr (assoc "standard::size" attributes
)) "0")))
963 ;; ... file mode flags
965 (let ((n (cdr (assoc "unix::mode" attributes
))))
967 (tramp-file-mode-from-int (string-to-number n
))
971 (if (equal (cdr (assoc "access::can-read" attributes
))
974 (if (equal (cdr (assoc "access::can-write" attributes
))
977 (if (equal (cdr (assoc "access::can-execute" attributes
))
980 ;; ... inode and device
982 (let ((n (cdr (assoc "unix::inode" attributes
))))
985 (tramp-get-inode (tramp-dissect-file-name filename
)))))
987 (let ((n (cdr (assoc "unix::device" attributes
))))
990 (tramp-get-device (tramp-dissect-file-name filename
)))))
992 ;; Return data gathered.
994 ;; 0. t for directory, string (name linked to) for
995 ;; symbolic link, or nil.
996 (or dirp res-symlink-target
)
997 ;; 1. Number of links to file.
1003 ;; 4. Last access time, as a list of integers.
1004 ;; 5. Last modification time, likewise.
1005 ;; 6. Last status change time, likewise.
1006 res-access res-mod res-change
1007 ;; 7. Size in bytes (-1, if number is out of range).
1011 ;; 9. t if file's gid would change if file were deleted
1014 ;; 10. Inode number.
1016 ;; 11. Device number.
1020 (defun tramp-gvfs-handle-file-directory-p (filename)
1021 "Like `file-directory-p' for Tramp files."
1022 (eq t
(tramp-compat-file-attribute-type
1023 (file-attributes (file-truename filename
)))))
1025 (defun tramp-gvfs-handle-file-executable-p (filename)
1026 "Like `file-executable-p' for Tramp files."
1027 (with-parsed-tramp-file-name filename nil
1028 (with-tramp-file-property v localname
"file-executable-p"
1029 (tramp-check-cached-permissions v ?x
))))
1031 (defun tramp-gvfs-handle-file-local-copy (filename)
1032 "Like `file-local-copy' for Tramp files."
1033 (with-parsed-tramp-file-name filename nil
1034 (let ((tmpfile (tramp-compat-make-temp-file filename
)))
1035 (unless (file-exists-p filename
)
1037 v tramp-file-missing
1038 "Cannot make local copy of non-existing file `%s'" filename
))
1039 (copy-file filename tmpfile
'ok-if-already-exists
'keep-time
)
1042 (defun tramp-gvfs-handle-file-name-all-completions (filename directory
)
1043 "Like `file-name-all-completions' for Tramp files."
1044 (unless (save-match-data (string-match "/" filename
))
1047 (with-parsed-tramp-file-name (expand-file-name directory
) nil
1048 (with-tramp-file-property v localname
"file-name-all-completions"
1049 (let ((result '("./" "../")))
1050 ;; Get a list of directories and files.
1051 (dolist (item (tramp-gvfs-get-directory-attributes directory
) result
)
1052 (if (string-equal (cdr (assoc "type" item
)) "directory")
1053 (push (file-name-as-directory (car item
)) result
)
1054 (push (car item
) result
)))))))))
1056 (defun tramp-gvfs-handle-file-notify-add-watch (file-name flags _callback
)
1057 "Like `file-notify-add-watch' for Tramp files."
1058 (setq file-name
(expand-file-name file-name
))
1059 (with-parsed-tramp-file-name file-name nil
1060 ;; We cannot watch directories, because `gvfs-monitor-dir' is not
1061 ;; supported for gvfs-mounted directories.
1062 (when (file-directory-p file-name
)
1064 v
'file-notify-error
"Monitoring not supported for `%s'" file-name
))
1065 (let* ((default-directory (file-name-directory file-name
))
1068 ((and (memq 'change flags
) (memq 'attribute-change flags
))
1069 '(created changed changes-done-hint moved deleted
1071 ((memq 'change flags
)
1072 '(created changed changes-done-hint moved deleted
))
1073 ((memq 'attribute-change flags
) '(attribute-changed))))
1075 "gvfs-monitor-file" (generate-new-buffer " *gvfs-monitor-file*")
1076 "gvfs-monitor-file" (tramp-gvfs-url-file-name file-name
))))
1077 (if (not (processp p
))
1079 v
'file-notify-error
"Monitoring not supported for `%s'" file-name
)
1081 v
6 "Run `%s', %S" (mapconcat 'identity
(process-command p
) " ") p
)
1082 (tramp-set-connection-property p
"vector" v
)
1083 (process-put p
'events events
)
1084 (process-put p
'watch-name localname
)
1085 (set-process-query-on-exit-flag p nil
)
1086 (set-process-filter p
'tramp-gvfs-monitor-file-process-filter
)
1087 ;; There might be an error if the monitor is not supported.
1088 ;; Give the filter a chance to read the output.
1089 (tramp-accept-process-output p
1)
1090 (unless (tramp-compat-process-live-p p
)
1092 v
'file-notify-error
"Monitoring not supported for `%s'" file-name
))
1095 (defun tramp-gvfs-monitor-file-process-filter (proc string
)
1096 "Read output from \"gvfs-monitor-file\" and add corresponding \
1097 file-notify events."
1098 (let* ((rest-string (process-get proc
'rest-string
))
1099 (dd (with-current-buffer (process-buffer proc
) default-directory
))
1100 (ddu (regexp-quote (tramp-gvfs-url-file-name dd
))))
1102 (tramp-message proc
10 "Previous string:\n%s" rest-string
))
1103 (tramp-message proc
6 "%S\n%s" proc string
)
1104 (setq string
(concat rest-string string
)
1105 ;; Attribute change is returned in unused wording.
1106 string
(replace-regexp-in-string
1107 "ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string
))
1108 (when (string-match "Monitoring not supported" string
)
1109 (delete-process proc
))
1111 (while (string-match
1113 "File Monitor Event:[\n\r]+"
1114 "File = \\([^\n\r]+\\)[\n\r]+"
1115 "Event = \\([^[:blank:]]+\\)[\n\r]+")
1117 (let ((file (match-string 1 string
))
1118 (action (intern-soft
1119 (replace-regexp-in-string
1120 "_" "-" (downcase (match-string 2 string
))))))
1121 (setq string
(replace-match "" nil nil string
))
1122 ;; File names are returned as URL paths. We must convert them.
1123 (when (string-match ddu file
)
1124 (setq file
(replace-match dd nil nil file
)))
1125 (while (string-match "%\\([0-9A-F]\\{2\\}\\)" file
)
1128 (char-to-string (string-to-number (match-string 1 file
) 16))
1130 ;; Usually, we would add an Emacs event now. Unfortunately,
1131 ;; `unread-command-events' does not accept several events at
1132 ;; once. Therefore, we apply the callback directly.
1133 (tramp-compat-funcall 'file-notify-callback
(list proc action file
))))
1135 ;; Save rest of the string.
1136 (when (zerop (length string
)) (setq string nil
))
1137 (when string
(tramp-message proc
10 "Rest string:\n%s" string
))
1138 (process-put proc
'rest-string string
)))
1140 (defun tramp-gvfs-handle-file-readable-p (filename)
1141 "Like `file-readable-p' for Tramp files."
1142 (with-parsed-tramp-file-name filename nil
1143 (with-tramp-file-property v localname
"file-readable-p"
1144 (tramp-check-cached-permissions v ?r
))))
1146 (defun tramp-gvfs-handle-file-writable-p (filename)
1147 "Like `file-writable-p' for Tramp files."
1148 (with-parsed-tramp-file-name filename nil
1149 (with-tramp-file-property v localname
"file-writable-p"
1150 (if (file-exists-p filename
)
1151 (tramp-check-cached-permissions v ?w
)
1152 ;; If file doesn't exist, check if directory is writable.
1153 (and (file-directory-p (file-name-directory filename
))
1154 (file-writable-p (file-name-directory filename
)))))))
1156 (defun tramp-gvfs-handle-make-directory (dir &optional parents
)
1157 "Like `make-directory' for Tramp files."
1158 (setq dir
(directory-file-name (expand-file-name dir
)))
1159 (with-parsed-tramp-file-name dir nil
1160 (tramp-flush-file-property v
(file-name-directory localname
))
1161 (tramp-flush-directory-property v localname
)
1163 (let ((ldir (file-name-directory dir
)))
1164 ;; Make missing directory parts. "gvfs-mkdir -p ..." does not
1166 (when (and parents
(not (file-directory-p ldir
)))
1167 (make-directory ldir parents
))
1169 (unless (tramp-gvfs-send-command
1170 v
"gvfs-mkdir" (tramp-gvfs-url-file-name dir
))
1171 (tramp-error v
'file-error
"Couldn't make directory %s" dir
))))))
1173 (defun tramp-gvfs-handle-rename-file
1174 (filename newname
&optional ok-if-already-exists
)
1175 "Like `rename-file' for Tramp files."
1176 ;; Check if both files are local -- invoke normal rename-file.
1177 ;; Otherwise, use Tramp from local system.
1178 (setq filename
(expand-file-name filename
))
1179 (setq newname
(expand-file-name newname
))
1180 ;; At least one file a Tramp file?
1181 (if (or (tramp-tramp-file-p filename
)
1182 (tramp-tramp-file-p newname
))
1183 (tramp-gvfs-do-copy-or-rename-file
1184 'rename filename newname ok-if-already-exists
1185 'keep-date
'preserve-uid-gid
)
1186 (tramp-run-real-handler
1187 'rename-file
(list filename newname ok-if-already-exists
))))
1189 (defun tramp-gvfs-handle-write-region
1190 (start end filename
&optional append visit lockname confirm
)
1191 "Like `write-region' for Tramp files."
1192 (with-parsed-tramp-file-name filename nil
1193 (when (and confirm
(file-exists-p filename
))
1194 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename
))
1195 (tramp-error v
'file-error
"File not overwritten")))
1197 (let ((tmpfile (tramp-compat-make-temp-file filename
)))
1198 (when (and append
(file-exists-p filename
))
1199 (copy-file filename tmpfile
'ok
))
1200 ;; We say `no-message' here because we don't want the visited file
1201 ;; modtime data to be clobbered from the temp file. We call
1202 ;; `set-visited-file-modtime' ourselves later on.
1203 (tramp-run-real-handler
1205 (if confirm
; don't pass this arg unless defined for backward compat.
1206 (list start end tmpfile append
'no-message lockname confirm
)
1207 (list start end tmpfile append
'no-message lockname
)))
1209 (rename-file tmpfile filename
'ok-if-already-exists
)
1211 (delete-file tmpfile
)
1213 v
'file-error
"Couldn't write region to `%s'" filename
))))
1215 (tramp-flush-file-property v
(file-name-directory localname
))
1216 (tramp-flush-file-property v localname
)
1218 ;; Set file modification time.
1219 (when (or (eq visit t
) (stringp visit
))
1220 (set-visited-file-modtime
1221 (tramp-compat-file-attribute-modification-time
1222 (file-attributes filename
))))
1225 (when (or (eq visit t
) (null visit
) (stringp visit
))
1226 (tramp-message v
0 "Wrote %s" filename
))
1227 (run-hooks 'tramp-handle-write-region-hook
)))
1230 ;; File name conversions.
1232 (defun tramp-gvfs-url-file-name (filename)
1233 "Return FILENAME in URL syntax."
1234 ;; "/" must NOT be hexlified.
1235 (let ((url-unreserved-chars (cons ?
/ url-unreserved-chars
))
1240 (if (tramp-tramp-file-p filename
)
1241 (with-parsed-tramp-file-name filename nil
1242 (when (string-equal "gdrive" method
)
1243 (setq method
"google-drive"))
1244 (when (and user
(string-match tramp-user-with-domain-regexp user
))
1246 (concat (match-string 2 user
) ";" (match-string 1 user
))))
1247 (url-parse-make-urlobj
1248 method
(and user
(url-hexify-string user
)) nil
1249 (tramp-file-name-real-host v
) (tramp-file-name-port v
)
1250 (and localname
(url-hexify-string localname
)) nil nil t
))
1251 (url-parse-make-urlobj
1252 "file" nil nil nil nil
1253 (url-hexify-string (file-truename filename
)) nil nil t
))))
1254 (when (tramp-tramp-file-p filename
)
1255 (with-parsed-tramp-file-name filename nil
1256 (tramp-message v
10 "remote file `%s' is URL `%s'" filename result
)))
1259 (defun tramp-gvfs-object-path (filename)
1260 "Create a D-Bus object path from FILENAME."
1261 (expand-file-name (dbus-escape-as-identifier filename
) tramp-gvfs-path-tramp
))
1263 (defun tramp-gvfs-file-name (object-path)
1264 "Retrieve file name from D-Bus OBJECT-PATH."
1265 (dbus-unescape-from-identifier
1266 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path
)))
1268 (defun tramp-bluez-address (device)
1269 "Return bluetooth device address from a given bluetooth DEVICE name."
1270 (when (stringp device
)
1271 (if (string-match tramp-ipv6-regexp device
)
1272 (match-string 0 device
)
1273 (cadr (assoc device
(tramp-bluez-list-devices))))))
1275 (defun tramp-bluez-device (address)
1276 "Return bluetooth device name from a given bluetooth device ADDRESS.
1277 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
1278 (when (stringp address
)
1279 (while (string-match "[][]" address
)
1280 (setq address
(replace-match "" t t address
)))
1282 (dolist (item (tramp-bluez-list-devices) result
)
1283 (when (string-match address
(cadr item
))
1284 (setq result
(car item
)))))))
1287 ;; D-Bus GVFS functions.
1289 (defun tramp-gvfs-handler-askpassword (message user domain flags
)
1290 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
1292 (tramp-gvfs-file-name (dbus-event-path-name last-input-event
)))
1296 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message
)
1297 (capitalize (match-string 1 message
))
1303 (with-parsed-tramp-file-name filename l
1304 (when (and (zerop (length user
))
1306 (zerop (logand flags tramp-gvfs-password-need-username
))))
1307 (setq user
(read-string "User name: ")))
1308 (when (and (zerop (length domain
))
1310 (zerop (logand flags tramp-gvfs-password-need-domain
))))
1311 (setq domain
(read-string "Domain name: ")))
1313 (tramp-message l
6 "%S %S %S %d" message user domain flags
)
1314 (unless (tramp-get-connection-property l
"first-password-request" nil
)
1315 (tramp-clear-passwd l
))
1317 (setq tramp-current-method l-method
1318 tramp-current-user user
1319 tramp-current-host l-host
1320 password
(tramp-read-passwd
1321 (tramp-get-connection-process l
) pw-prompt
))
1324 (if (stringp password
)
1326 t
;; password handled.
1327 nil
;; no abort of D-Bus.
1329 (tramp-file-name-real-user l
)
1331 nil
;; not anonymous.
1332 0) ;; no password save.
1333 ;; No password provided.
1334 (list nil t
"" (tramp-file-name-real-user l
) domain nil
0)))
1336 ;; When QUIT is raised, we shall return this information to D-Bus.
1337 (quit (list nil t
"" "" "" nil
0)))))
1339 (defun tramp-gvfs-handler-askquestion (message choices
)
1340 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
1341 (save-window-excursion
1342 (let ((enable-recursive-minibuffers t
)
1346 (with-parsed-tramp-file-name
1347 (tramp-gvfs-file-name (dbus-event-path-name last-input-event
)) nil
1348 (tramp-message v
6 "%S %S" message choices
)
1350 ;; In theory, there can be several choices. Until now,
1351 ;; there is only the question whether to accept an unknown
1354 ;; Preserve message for `progress-reporter'.
1355 (with-temp-message ""
1357 (pop-to-buffer (current-buffer))
1358 (setq choice
(if (yes-or-no-p (concat (car choices
) " ")) 0 1))
1359 (tramp-message v
6 "%d" choice
)))
1361 ;; When the choice is "no", we set a dummy fuse-mountpoint
1362 ;; in order to leave the timeout.
1363 (unless (zerop choice
)
1364 (tramp-set-file-property v
"/" "fuse-mountpoint" "/"))
1368 nil
;; no abort of D-Bus.
1371 ;; When QUIT is raised, we shall return this information to D-Bus.
1372 (quit (list nil t
0))))))
1374 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
1375 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
1376 \"org.gtk.vfs.MountTracker.unmounted\" signals."
1378 (let ((signal-name (dbus-event-member-name last-input-event
))
1380 ;; Jump over the first elements of the mount info. Since there
1381 ;; were changes in the entries, we cannot access dedicated
1383 (while (stringp (car elt
)) (setq elt
(cdr elt
)))
1384 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string (cadr elt
)))
1385 (mount-spec (caddr elt
))
1386 (default-location (tramp-gvfs-dbus-byte-array-to-string
1388 (method (tramp-gvfs-dbus-byte-array-to-string
1389 (cadr (assoc "type" (cadr mount-spec
)))))
1390 (user (tramp-gvfs-dbus-byte-array-to-string
1391 (cadr (assoc "user" (cadr mount-spec
)))))
1392 (domain (tramp-gvfs-dbus-byte-array-to-string
1393 (cadr (assoc "domain" (cadr mount-spec
)))))
1394 (host (tramp-gvfs-dbus-byte-array-to-string
1395 (cadr (or (assoc "host" (cadr mount-spec
))
1396 (assoc "server" (cadr mount-spec
))))))
1397 (port (tramp-gvfs-dbus-byte-array-to-string
1398 (cadr (assoc "port" (cadr mount-spec
)))))
1399 (ssl (tramp-gvfs-dbus-byte-array-to-string
1400 (cadr (assoc "ssl" (cadr mount-spec
)))))
1402 (tramp-gvfs-dbus-byte-array-to-string
1404 (tramp-gvfs-dbus-byte-array-to-string
1405 (or (cadr (assoc "share" (cadr mount-spec
)))
1406 (cadr (assoc "volume" (cadr mount-spec
))))))))
1407 (when (string-match "^\\(afp\\|smb\\)" method
)
1408 (setq method
(match-string 1 method
)))
1409 (when (string-equal "obex" method
)
1410 (setq host
(tramp-bluez-device host
)))
1411 (when (and (string-equal "dav" method
) (string-equal "true" ssl
))
1412 (setq method
"davs"))
1413 (when (string-equal "google-drive" method
)
1414 (setq method
"gdrive"))
1415 (unless (zerop (length domain
))
1416 (setq user
(concat user tramp-prefix-domain-format domain
)))
1417 (unless (zerop (length port
))
1418 (setq host
(concat host tramp-prefix-port-format port
)))
1419 (with-parsed-tramp-file-name
1420 (tramp-make-tramp-file-name method user host
"") nil
1423 signal-name
(tramp-gvfs-stringify-dbus-message mount-info
))
1424 (tramp-set-file-property v
"/" "list-mounts" 'undef
)
1425 (if (string-equal (downcase signal-name
) "unmounted")
1426 (tramp-flush-file-property v
"/")
1427 ;; Set prefix, mountpoint and location.
1428 (unless (string-equal prefix
"/")
1429 (tramp-set-file-property v
"/" "prefix" prefix
))
1430 (tramp-set-file-property v
"/" "fuse-mountpoint" fuse-mountpoint
)
1431 (tramp-set-connection-property
1432 v
"default-location" default-location
)))))))
1434 (when tramp-gvfs-enabled
1435 (dbus-register-signal
1436 :session nil tramp-gvfs-path-mounttracker
1437 tramp-gvfs-interface-mounttracker
"mounted"
1438 'tramp-gvfs-handler-mounted-unmounted
)
1439 (dbus-register-signal
1440 :session nil tramp-gvfs-path-mounttracker
1441 tramp-gvfs-interface-mounttracker
"Mounted"
1442 'tramp-gvfs-handler-mounted-unmounted
)
1444 (dbus-register-signal
1445 :session nil tramp-gvfs-path-mounttracker
1446 tramp-gvfs-interface-mounttracker
"unmounted"
1447 'tramp-gvfs-handler-mounted-unmounted
)
1448 (dbus-register-signal
1449 :session nil tramp-gvfs-path-mounttracker
1450 tramp-gvfs-interface-mounttracker
"Unmounted"
1451 'tramp-gvfs-handler-mounted-unmounted
))
1453 (defun tramp-gvfs-connection-mounted-p (vec)
1454 "Check, whether the location is already mounted."
1456 (tramp-get-file-property vec
"/" "fuse-mountpoint" nil
)
1460 (with-tramp-file-property vec
"/" "list-mounts"
1461 (with-tramp-dbus-call-method vec t
1462 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1463 tramp-gvfs-interface-mounttracker tramp-gvfs-listmounts
))
1465 ;; Jump over the first elements of the mount info. Since there
1466 ;; were changes in the entries, we cannot access dedicated
1468 (while (stringp (car elt
)) (setq elt
(cdr elt
)))
1469 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string
1471 (mount-spec (caddr elt
))
1472 (default-location (tramp-gvfs-dbus-byte-array-to-string
1474 (method (tramp-gvfs-dbus-byte-array-to-string
1475 (cadr (assoc "type" (cadr mount-spec
)))))
1476 (user (tramp-gvfs-dbus-byte-array-to-string
1477 (cadr (assoc "user" (cadr mount-spec
)))))
1478 (domain (tramp-gvfs-dbus-byte-array-to-string
1479 (cadr (assoc "domain" (cadr mount-spec
)))))
1480 (host (tramp-gvfs-dbus-byte-array-to-string
1481 (cadr (or (assoc "host" (cadr mount-spec
))
1482 (assoc "server" (cadr mount-spec
))))))
1483 (port (tramp-gvfs-dbus-byte-array-to-string
1484 (cadr (assoc "port" (cadr mount-spec
)))))
1485 (ssl (tramp-gvfs-dbus-byte-array-to-string
1486 (cadr (assoc "ssl" (cadr mount-spec
)))))
1488 (tramp-gvfs-dbus-byte-array-to-string
1490 (tramp-gvfs-dbus-byte-array-to-string
1492 (cadr (assoc "share" (cadr mount-spec
)))
1493 (cadr (assoc "volume" (cadr mount-spec
))))))))
1494 (when (string-match "^\\(afp\\|smb\\)" method
)
1495 (setq method
(match-string 1 method
)))
1496 (when (string-equal "obex" method
)
1497 (setq host
(tramp-bluez-device host
)))
1498 (when (and (string-equal "dav" method
) (string-equal "true" ssl
))
1499 (setq method
"davs"))
1500 (when (string-equal "google-drive" method
)
1501 (setq method
"gdrive"))
1502 (when (and (string-equal "synce" method
) (zerop (length user
)))
1503 (setq user
(or (tramp-file-name-user vec
) "")))
1504 (unless (zerop (length domain
))
1505 (setq user
(concat user tramp-prefix-domain-format domain
)))
1506 (unless (zerop (length port
))
1507 (setq host
(concat host tramp-prefix-port-format port
)))
1509 (string-equal method
(tramp-file-name-method vec
))
1510 (string-equal user
(or (tramp-file-name-user vec
) ""))
1511 (string-equal host
(tramp-file-name-host vec
))
1512 (string-match (concat "^" (regexp-quote prefix
))
1513 (tramp-file-name-localname vec
)))
1514 ;; Set prefix, mountpoint and location.
1515 (unless (string-equal prefix
"/")
1516 (tramp-set-file-property vec
"/" "prefix" prefix
))
1517 (tramp-set-file-property vec
"/" "fuse-mountpoint" fuse-mountpoint
)
1518 (tramp-set-connection-property
1519 vec
"default-location" default-location
)
1520 (throw 'mounted t
)))))))
1522 (defun tramp-gvfs-mount-spec-entry (key value
)
1523 "Construct a mount-spec entry to be used in a mount_spec.
1524 It was \"a(say)\", but has changed to \"a{sv})\"."
1525 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature
)
1526 (list :dict-entry key
1527 (list :variant
(tramp-gvfs-dbus-string-to-byte-array value
)))
1528 (list :struct key
(tramp-gvfs-dbus-string-to-byte-array value
))))
1530 (defun tramp-gvfs-mount-spec (vec)
1531 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1532 (let* ((method (tramp-file-name-method vec
))
1533 (user (tramp-file-name-real-user vec
))
1534 (domain (tramp-file-name-domain vec
))
1535 (host (tramp-file-name-real-host vec
))
1536 (port (tramp-file-name-port vec
))
1537 (localname (tramp-file-name-localname vec
))
1538 (share (when (string-match "^/?\\([^/]+\\)" localname
)
1539 (match-string 1 localname
)))
1540 (ssl (if (string-match "^davs" method
) "true" "false"))
1544 ((string-equal "smb" method
)
1545 (list (tramp-gvfs-mount-spec-entry "type" "smb-share")
1546 (tramp-gvfs-mount-spec-entry "server" host
)
1547 (tramp-gvfs-mount-spec-entry "share" share
)))
1548 ((string-equal "obex" method
)
1549 (list (tramp-gvfs-mount-spec-entry "type" method
)
1550 (tramp-gvfs-mount-spec-entry
1551 "host" (concat "[" (tramp-bluez-address host
) "]"))))
1552 ((string-match "\\`dav" method
)
1553 (list (tramp-gvfs-mount-spec-entry "type" "dav")
1554 (tramp-gvfs-mount-spec-entry "host" host
)
1555 (tramp-gvfs-mount-spec-entry "ssl" ssl
)))
1556 ((string-equal "afp" method
)
1557 (list (tramp-gvfs-mount-spec-entry "type" "afp-volume")
1558 (tramp-gvfs-mount-spec-entry "host" host
)
1559 (tramp-gvfs-mount-spec-entry "volume" share
)))
1560 ((string-equal "gdrive" method
)
1561 (list (tramp-gvfs-mount-spec-entry "type" "google-drive")
1562 (tramp-gvfs-mount-spec-entry "host" host
)))
1564 (list (tramp-gvfs-mount-spec-entry "type" method
)
1565 (tramp-gvfs-mount-spec-entry "host" host
))))
1567 (list (tramp-gvfs-mount-spec-entry "user" user
)))
1569 (list (tramp-gvfs-mount-spec-entry "domain" domain
)))
1571 (list (tramp-gvfs-mount-spec-entry
1572 "port" (number-to-string port
))))))
1574 (if (and (string-match "\\`dav" method
)
1575 (string-match "^/?[^/]+" localname
))
1576 (match-string 0 localname
)
1580 `(:struct
,(tramp-gvfs-dbus-string-to-byte-array mount-pref
) ,mount-spec
)))
1583 ;; Connection functions.
1585 (defun tramp-gvfs-get-remote-uid (vec id-format
)
1586 "The uid of the remote connection VEC, in ID-FORMAT.
1587 ID-FORMAT valid values are `string' and `integer'."
1588 (with-tramp-connection-property vec
(format "uid-%s" id-format
)
1589 (let ((method (tramp-file-name-method vec
))
1590 (user (tramp-file-name-user vec
))
1591 (host (tramp-file-name-host vec
))
1593 (tramp-get-connection-property vec
"default-location" nil
)))
1595 ((and user
(equal id-format
'string
)) user
)
1597 (tramp-compat-file-attribute-user-id
1599 (tramp-make-tramp-file-name method user host localname
) id-format
)))
1600 ((equal id-format
'integer
) tramp-unknown-id-integer
)
1601 ((equal id-format
'string
) tramp-unknown-id-string
)))))
1603 (defun tramp-gvfs-get-remote-gid (vec id-format
)
1604 "The gid of the remote connection VEC, in ID-FORMAT.
1605 ID-FORMAT valid values are `string' and `integer'."
1606 (with-tramp-connection-property vec
(format "gid-%s" id-format
)
1607 (let ((method (tramp-file-name-method vec
))
1608 (user (tramp-file-name-user vec
))
1609 (host (tramp-file-name-host vec
))
1611 (tramp-get-connection-property vec
"default-location" nil
)))
1614 (tramp-compat-file-attribute-group-id
1616 (tramp-make-tramp-file-name method user host localname
) id-format
)))
1617 ((equal id-format
'integer
) tramp-unknown-id-integer
)
1618 ((equal id-format
'string
) tramp-unknown-id-string
)))))
1620 (defvar tramp-gvfs-get-remote-uid-gid-in-progress nil
1621 "Indication, that remote uid and gid determination is in progress.")
1623 (defun tramp-gvfs-maybe-open-connection (vec)
1624 "Maybe open a connection VEC.
1625 Does not do anything if a connection is already open, but re-opens the
1626 connection if a previous connection has died for some reason."
1627 (tramp-check-proper-method-and-host vec
)
1629 ;; We set the file name, in case there are incoming D-Bus signals or
1631 (setq tramp-gvfs-dbus-event-vector vec
)
1633 ;; For password handling, we need a process bound to the connection
1634 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1636 (unless (get-buffer-process (tramp-get-connection-buffer vec
))
1637 (let ((p (make-network-process
1638 :name
(tramp-buffer-name vec
)
1639 :buffer
(tramp-get-connection-buffer vec
)
1640 :server t
:host
'local
:service t
:noquery t
)))
1641 (set-process-query-on-exit-flag p nil
)))
1643 (unless (tramp-gvfs-connection-mounted-p vec
)
1644 (let* ((method (tramp-file-name-method vec
))
1645 (user (tramp-file-name-user vec
))
1646 (host (tramp-file-name-host vec
))
1647 (localname (tramp-file-name-localname vec
))
1649 (tramp-gvfs-object-path
1650 (tramp-make-tramp-file-name method user host
""))))
1652 (when (and (string-equal method
"afp")
1653 (string-equal localname
"/"))
1654 (tramp-error vec
'file-error
"Filename must contain an AFP volume"))
1656 (when (and (string-equal method
"smb")
1657 (string-equal localname
"/"))
1658 (tramp-error vec
'file-error
"Filename must contain a Windows share"))
1660 (with-tramp-progress-reporter
1662 (if (zerop (length user
))
1663 (format "Opening connection for %s using %s" host method
)
1664 (format "Opening connection for %s@%s using %s" user host method
))
1666 ;; Enable `auth-source'.
1667 (tramp-set-connection-property vec
"first-password-request" t
)
1669 ;; There will be a callback of "askPassword" when a password is
1671 (dbus-register-method
1672 :session dbus-service-emacs object-path
1673 tramp-gvfs-interface-mountoperation
"askPassword"
1674 'tramp-gvfs-handler-askpassword
)
1675 (dbus-register-method
1676 :session dbus-service-emacs object-path
1677 tramp-gvfs-interface-mountoperation
"AskPassword"
1678 'tramp-gvfs-handler-askpassword
)
1680 ;; There could be a callback of "askQuestion" when adding fingerprint.
1681 (dbus-register-method
1682 :session dbus-service-emacs object-path
1683 tramp-gvfs-interface-mountoperation
"askQuestion"
1684 'tramp-gvfs-handler-askquestion
)
1685 (dbus-register-method
1686 :session dbus-service-emacs object-path
1687 tramp-gvfs-interface-mountoperation
"AskQuestion"
1688 'tramp-gvfs-handler-askquestion
)
1690 ;; The call must be asynchronously, because of the "askPassword"
1691 ;; or "askQuestion"callbacks.
1692 (if (string-match "(so)$" tramp-gvfs-mountlocation-signature
)
1693 (with-tramp-dbus-call-method vec nil
1694 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1695 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1696 (tramp-gvfs-mount-spec vec
)
1697 `(:struct
:string
,(dbus-get-unique-name :session
)
1698 :object-path
,object-path
))
1699 (with-tramp-dbus-call-method vec nil
1700 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1701 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1702 (tramp-gvfs-mount-spec vec
)
1703 :string
(dbus-get-unique-name :session
) :object-path object-path
))
1705 ;; We must wait, until the mount is applied. This will be
1706 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1709 ((or (tramp-get-method-parameter vec
'tramp-connection-timeout
)
1710 tramp-connection-timeout
)
1711 (if (zerop (length (tramp-file-name-user vec
)))
1714 "Timeout reached mounting %s using %s" host method
)
1717 "Timeout reached mounting %s@%s using %s" user host method
)))
1718 (while (not (tramp-get-file-property vec
"/" "fuse-mountpoint" nil
))
1719 (read-event nil nil
0.1)))
1721 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1722 ;; is marked with the fuse-mountpoint "/". We shall react.
1724 (tramp-get-file-property vec
"/" "fuse-mountpoint" "") "/")
1725 (tramp-error vec
'file-error
"FUSE mount denied"))
1727 ;; Set connection-local variables.
1728 (tramp-set-connection-local-variables vec
)
1730 ;; Mark it as connected.
1731 (tramp-set-connection-property
1732 (tramp-get-connection-process vec
) "connected" t
))))
1734 ;; In `tramp-check-cached-permissions', the connection properties
1735 ;; {uig,gid}-{integer,string} are used. We set them to proper values.
1736 (unless tramp-gvfs-get-remote-uid-gid-in-progress
1737 (let ((tramp-gvfs-get-remote-uid-gid-in-progress t
))
1738 (tramp-gvfs-get-remote-uid vec
'integer
)
1739 (tramp-gvfs-get-remote-gid vec
'integer
)
1740 (tramp-gvfs-get-remote-uid vec
'string
)
1741 (tramp-gvfs-get-remote-gid vec
'string
))))
1743 (defun tramp-gvfs-send-command (vec command
&rest args
)
1744 "Send the COMMAND with its ARGS to connection VEC.
1745 COMMAND is usually a command from the gvfs-* utilities.
1746 `call-process' is applied, and it returns t if the return code is zero."
1747 (let* ((locale (tramp-get-local-locale vec
))
1748 (process-environment
1750 `(,(format "LANG=%s" locale
)
1751 ,(format "LANGUAGE=%s" locale
)
1752 ,(format "LC_ALL=%s" locale
))
1753 process-environment
)))
1754 (with-current-buffer (tramp-get-connection-buffer vec
)
1755 (tramp-gvfs-maybe-open-connection vec
)
1757 (or (zerop (apply 'tramp-call-process vec command nil t nil args
))
1758 ;; Remove information about mounted connection.
1759 (and (tramp-flush-file-property vec
"/") nil
)))))
1762 ;; D-Bus BLUEZ functions.
1764 (defun tramp-bluez-list-devices ()
1765 "Return all discovered bluetooth devices as list.
1766 Every entry is a list (NAME ADDRESS).
1768 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1769 discovery happened more time before indicated there, a rescan will be
1770 started, which lasts some ten seconds. Otherwise, cached results will
1772 ;; Reset the scanned devices list if time has passed.
1773 (and (integerp tramp-bluez-discover-devices-timeout
)
1774 (integerp tramp-bluez-discovery
)
1775 (> (tramp-time-diff (current-time) tramp-bluez-discovery
)
1776 tramp-bluez-discover-devices-timeout
)
1777 (setq tramp-bluez-devices nil
))
1779 ;; Rescan if needed.
1780 (unless tramp-bluez-devices
1782 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1783 :system tramp-bluez-service
"/"
1784 tramp-bluez-interface-manager
"DefaultAdapter")))
1785 (setq tramp-bluez-devices nil
1786 tramp-bluez-discovery t
)
1787 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1788 :system tramp-bluez-service object-path
1789 tramp-bluez-interface-adapter
"StartDiscovery")
1790 (while tramp-bluez-discovery
1791 (read-event nil nil
0.1))))
1792 (setq tramp-bluez-discovery
(current-time))
1793 (tramp-message tramp-gvfs-dbus-event-vector
10 "%s" tramp-bluez-devices
)
1794 tramp-bluez-devices
)
1796 (defun tramp-bluez-property-changed (property value
)
1797 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1798 (tramp-message tramp-gvfs-dbus-event-vector
6 "%s %s" property value
)
1800 ((string-equal property
"Discovering")
1802 ;; "Discovering" FALSE means discovery run has been completed.
1803 ;; We stop it, because we don't need another run.
1804 (setq tramp-bluez-discovery nil
)
1805 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1806 :system tramp-bluez-service
(dbus-event-path-name last-input-event
)
1807 tramp-bluez-interface-adapter
"StopDiscovery")))))
1809 (when tramp-gvfs-enabled
1810 (dbus-register-signal
1811 :system nil nil tramp-bluez-interface-adapter
"PropertyChanged"
1812 'tramp-bluez-property-changed
))
1814 (defun tramp-bluez-device-found (device args
)
1815 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1816 (tramp-message tramp-gvfs-dbus-event-vector
6 "%s %s" device args
)
1817 (let ((alias (car (cadr (assoc "Alias" args
))))
1818 (address (car (cadr (assoc "Address" args
)))))
1819 ;; Maybe we shall check the device class for being a proper
1820 ;; device, and call also SDP in order to find the obex service.
1821 (add-to-list 'tramp-bluez-devices
(list alias address
))))
1823 (when tramp-gvfs-enabled
1824 (dbus-register-signal
1825 :system nil nil tramp-bluez-interface-adapter
"DeviceFound"
1826 'tramp-bluez-device-found
))
1828 (defun tramp-bluez-parse-device-names (_ignore)
1829 "Return a list of (nil host) tuples allowed to access."
1831 (lambda (x) (list nil
(car x
)))
1832 (tramp-bluez-list-devices)))
1834 ;; Add completion function for OBEX method.
1835 (when (and tramp-gvfs-enabled
1836 (member tramp-bluez-service
(dbus-list-known-names :system
)))
1837 (tramp-set-completion-function
1838 "obex" '((tramp-bluez-parse-device-names ""))))
1841 ;; D-Bus zeroconf functions.
1843 (defun tramp-zeroconf-parse-device-names (service)
1844 "Return a list of (user host) tuples allowed to access."
1847 (let ((host (zeroconf-service-host x
))
1848 (port (zeroconf-service-port x
))
1849 (text (zeroconf-service-txt x
))
1852 (setq host
(format "%s%s%d" host tramp-prefix-port-regexp port
)))
1853 ;; A user is marked in a TXT field like "u=guest".
1855 (when (string-match "u=\\(.+\\)$" (car text
))
1856 (setq user
(match-string 1 (car text
))))
1857 (setq text
(cdr text
)))
1859 (zeroconf-list-services service
)))
1861 ;; We use the TRIM argument of `split-string', which exist since Emacs
1862 ;; 24.4. I mask this for older Emacs versions, there is no harm.
1863 (defun tramp-gvfs-parse-device-names (service)
1864 "Return a list of (user host) tuples allowed to access.
1865 This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi."
1868 (tramp-compat-funcall
1870 (shell-command-to-string (format "avahi-browse -trkp %s" service
))
1871 "[\n\r]+" 'omit
"^\\+;.*$"))))
1875 (let* ((list (split-string x
";"))
1878 (text (tramp-compat-funcall
1879 'split-string
(nth 9 list
) "\" \"" 'omit
"\""))
1881 ; (when (and port (not (string-equal port "0")))
1882 ; (setq host (format "%s%s%s" host tramp-prefix-port-regexp port)))
1883 ;; A user is marked in a TXT field like "u=guest".
1885 (when (string-match "u=\\(.+\\)$" (car text
))
1886 (setq user
(match-string 1 (car text
))))
1887 (setq text
(cdr text
)))
1891 ;; Add completion functions for AFP, DAV, DAVS, SFTP and SMB methods.
1892 (when tramp-gvfs-enabled
1893 ;; Suppress D-Bus error messages.
1894 (let (tramp-gvfs-dbus-event-vector)
1895 (zeroconf-init tramp-gvfs-zeroconf-domain
)
1896 (if (zeroconf-list-service-types)
1898 (tramp-set-completion-function
1899 "afp" '((tramp-zeroconf-parse-device-names "_afpovertcp._tcp")))
1900 (tramp-set-completion-function
1901 "dav" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
1902 (tramp-set-completion-function
1903 "davs" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
1904 (tramp-set-completion-function
1905 "sftp" '((tramp-zeroconf-parse-device-names "_ssh._tcp")
1906 (tramp-zeroconf-parse-device-names "_workstation._tcp")))
1907 (when (member "smb" tramp-gvfs-methods
)
1908 (tramp-set-completion-function
1909 "smb" '((tramp-zeroconf-parse-device-names "_smb._tcp")))))
1911 (when (executable-find "avahi-browse")
1912 (tramp-set-completion-function
1913 "afp" '((tramp-gvfs-parse-device-names "_afpovertcp._tcp")))
1914 (tramp-set-completion-function
1915 "dav" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
1916 (tramp-set-completion-function
1917 "davs" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
1918 (tramp-set-completion-function
1919 "sftp" '((tramp-gvfs-parse-device-names "_ssh._tcp")
1920 (tramp-gvfs-parse-device-names "_workstation._tcp")))
1921 (when (member "smb" tramp-gvfs-methods
)
1922 (tramp-set-completion-function
1923 "smb" '((tramp-gvfs-parse-device-names "_smb._tcp"))))))))
1926 ;; D-Bus SYNCE functions.
1928 (defun tramp-synce-list-devices ()
1929 "Return all discovered synce devices as list.
1930 They are retrieved from the hal daemon."
1931 (let (tramp-synce-devices)
1933 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1934 :system tramp-hal-service tramp-hal-path-manager
1935 tramp-hal-interface-manager
"GetAllDevices"))
1936 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1937 :system tramp-hal-service device tramp-hal-interface-device
1938 "PropertyExists" "sync.plugin")
1940 (with-tramp-dbus-call-method
1941 tramp-gvfs-dbus-event-vector t
1942 :system tramp-hal-service device tramp-hal-interface-device
1943 "GetPropertyString" "pda.pocketpc.name")))
1944 (unless (member prop tramp-synce-devices
)
1945 (push prop tramp-synce-devices
)))))
1946 (tramp-message tramp-gvfs-dbus-event-vector
10 "%s" tramp-synce-devices
)
1947 tramp-synce-devices
))
1949 (defun tramp-synce-parse-device-names (_ignore)
1950 "Return a list of (nil host) tuples allowed to access."
1952 (lambda (x) (list nil x
))
1953 (tramp-synce-list-devices)))
1955 ;; Add completion function for SYNCE method.
1956 (when tramp-gvfs-enabled
1957 (tramp-set-completion-function
1958 "synce" '((tramp-synce-parse-device-names ""))))
1960 (add-hook 'tramp-unload-hook
1962 (unload-feature 'tramp-gvfs
'force
)))
1964 (provide 'tramp-gvfs
)
1968 ;; * Host name completion for existing mount points (afp-server,
1969 ;; smb-server) or via smb-network.
1971 ;; * Check, how two shares of the same SMB server can be mounted in
1974 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1977 ;; * Implement obex for other serial communication but bluetooth.
1979 ;;; tramp-gvfs.el ends here