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", "obex", "sftp" and "synce". Note that with "obex" it might
53 ;; be necessary to pair with the other bluetooth device, if it hasn't
54 ;; been done already. There might be also some few seconds delay in
55 ;; 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 '("afp" "dav" "davs" "obex" "sftp" "synce")
114 "List of methods for remote files, accessed with GVFS."
117 :type '(repeat (choice (const "afp")
126 ;; Add a default for `tramp-default-user-alist'. Rule: For the SYNCE
127 ;; method, no user is chosen.
129 (add-to-list 'tramp-default-user-alist '("\\`synce\\'" nil nil))
132 (defcustom tramp-gvfs-zeroconf-domain "local"
133 "Zeroconf domain to be used for discovering services, like host names."
138 ;; Add the methods to `tramp-methods', in order to allow minibuffer
141 (when (featurep 'dbusbind)
142 (dolist (elt tramp-gvfs-methods)
143 (unless (assoc elt tramp-methods)
144 (add-to-list 'tramp-methods (cons elt nil)))))
146 (defconst tramp-gvfs-path-tramp (concat dbus-path-emacs "/Tramp")
147 "The preceding object path for own objects.")
149 (defconst tramp-gvfs-service-daemon "org.gtk.vfs.Daemon"
150 "The well known name of the GVFS daemon.")
152 ;; D-Bus integration is available since Emacs 23 on some system types.
153 ;; We don't call `dbus-ping', because this would load dbus.el.
154 (defconst tramp-gvfs-enabled
156 (and (featurep 'dbusbind)
157 (tramp-compat-funcall 'dbus-get-unique-name :system)
158 (tramp-compat-funcall 'dbus-get-unique-name :session)
159 (or (tramp-compat-process-running-p "gvfs-fuse-daemon")
160 (tramp-compat-process-running-p "gvfsd-fuse"))))
161 "Non-nil when GVFS is available.")
163 (defconst tramp-gvfs-path-mounttracker "/org/gtk/vfs/mounttracker"
164 "The object path of the GVFS daemon.")
166 (defconst tramp-gvfs-interface-mounttracker "org.gtk.vfs.MountTracker"
167 "The mount tracking interface in the GVFS daemon.")
169 ;; Introspection data exist since GVFS 1.14. If there are no such
170 ;; data, we expect an earlier interface.
171 (defconst tramp-gvfs-methods-mounttracker
172 (and tramp-gvfs-enabled
173 (dbus-introspect-get-method-names
174 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
175 tramp-gvfs-interface-mounttracker))
176 "The list of supported methods of the mount tracking interface.")
178 (defconst tramp-gvfs-listmounts
179 (if (member "ListMounts" tramp-gvfs-methods-mounttracker)
182 "The name of the \"listMounts\" method.
183 It has been changed in GVFS 1.14.")
185 (defconst tramp-gvfs-mountlocation
186 (if (member "MountLocation" tramp-gvfs-methods-mounttracker)
189 "The name of the \"mountLocation\" method.
190 It has been changed in GVFS 1.14.")
192 (defconst tramp-gvfs-mountlocation-signature
193 (and tramp-gvfs-enabled
194 (dbus-introspect-get-signature
195 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
196 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation))
197 "The D-Bus signature of the \"mountLocation\" method.
198 It has been changed in GVFS 1.14.")
200 ;; <interface name='org.gtk.vfs.MountTracker'>
201 ;; <method name='listMounts'>
202 ;; <arg name='mount_info_list'
203 ;; type='a{sosssssbay{aya{say}}ay}'
206 ;; <method name='mountLocation'>
207 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
208 ;; <arg name='dbus_id' type='s' direction='in'/>
209 ;; <arg name='object_path' type='o' direction='in'/>
211 ;; <signal name='mounted'>
212 ;; <arg name='mount_info'
213 ;; type='{sosssssbay{aya{say}}ay}'/>
215 ;; <signal name='unmounted'>
216 ;; <arg name='mount_info'
217 ;; type='{sosssssbay{aya{say}}ay}'/>
223 ;; OBJECT_PATH object_path
224 ;; STRING display_name
225 ;; STRING stable_name
226 ;; STRING x_content_types Since GVFS 1.0 only !!!
228 ;; STRING preferred_filename_encoding
229 ;; BOOLEAN user_visible
230 ;; ARRAY BYTE fuse_mountpoint
232 ;; ARRAY BYTE mount_prefix
234 ;; STRUCT mount_spec_item
235 ;; STRING key (type, user, domain, host, server,
236 ;; share, volume, port, ssl)
238 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
240 (defconst tramp-gvfs-interface-mountoperation "org.gtk.vfs.MountOperation"
241 "Used by the dbus-proxying implementation of GMountOperation.")
243 ;; <interface name='org.gtk.vfs.MountOperation'>
244 ;; <method name='askPassword'>
245 ;; <arg name='message' type='s' direction='in'/>
246 ;; <arg name='default_user' type='s' direction='in'/>
247 ;; <arg name='default_domain' type='s' direction='in'/>
248 ;; <arg name='flags' type='u' direction='in'/>
249 ;; <arg name='handled' type='b' direction='out'/>
250 ;; <arg name='aborted' type='b' direction='out'/>
251 ;; <arg name='password' type='s' direction='out'/>
252 ;; <arg name='username' type='s' direction='out'/>
253 ;; <arg name='domain' type='s' direction='out'/>
254 ;; <arg name='anonymous' type='b' direction='out'/>
255 ;; <arg name='password_save' type='u' direction='out'/>
257 ;; <method name='askQuestion'>
258 ;; <arg name='message' type='s' direction='in'/>
259 ;; <arg name='choices' type='as' direction='in'/>
260 ;; <arg name='handled' type='b' direction='out'/>
261 ;; <arg name='aborted' type='b' direction='out'/>
262 ;; <arg name='choice' type='u' direction='out'/>
266 ;; The following flags are used in "askPassword". They are defined in
267 ;; /usr/include/glib-2.0/gio/gioenums.h.
269 (defconst tramp-gvfs-password-need-password 1
270 "Operation requires a password.")
272 (defconst tramp-gvfs-password-need-username 2
273 "Operation requires a username.")
275 (defconst tramp-gvfs-password-need-domain 4
276 "Operation requires a domain.")
278 (defconst tramp-gvfs-password-saving-supported 8
279 "Operation supports saving settings.")
281 (defconst tramp-gvfs-password-anonymous-supported 16
282 "Operation supports anonymous users.")
284 (defconst tramp-bluez-service "org.bluez"
285 "The well known name of the BLUEZ service.")
287 (defconst tramp-bluez-interface-manager "org.bluez.Manager"
288 "The manager interface of the BLUEZ daemon.")
290 ;; <interface name='org.bluez.Manager'>
291 ;; <method name='DefaultAdapter'>
292 ;; <arg type='o' direction='out'/>
294 ;; <method name='FindAdapter'>
295 ;; <arg type='s' direction='in'/>
296 ;; <arg type='o' direction='out'/>
298 ;; <method name='ListAdapters'>
299 ;; <arg type='ao' direction='out'/>
301 ;; <signal name='AdapterAdded'>
304 ;; <signal name='AdapterRemoved'>
307 ;; <signal name='DefaultAdapterChanged'>
312 (defconst tramp-bluez-interface-adapter "org.bluez.Adapter"
313 "The adapter interface of the BLUEZ daemon.")
315 ;; <interface name='org.bluez.Adapter'>
316 ;; <method name='GetProperties'>
317 ;; <arg type='a{sv}' direction='out'/>
319 ;; <method name='SetProperty'>
320 ;; <arg type='s' direction='in'/>
321 ;; <arg type='v' direction='in'/>
323 ;; <method name='RequestMode'>
324 ;; <arg type='s' direction='in'/>
326 ;; <method name='ReleaseMode'/>
327 ;; <method name='RequestSession'/>
328 ;; <method name='ReleaseSession'/>
329 ;; <method name='StartDiscovery'/>
330 ;; <method name='StopDiscovery'/>
331 ;; <method name='ListDevices'>
332 ;; <arg type='ao' direction='out'/>
334 ;; <method name='CreateDevice'>
335 ;; <arg type='s' direction='in'/>
336 ;; <arg type='o' direction='out'/>
338 ;; <method name='CreatePairedDevice'>
339 ;; <arg type='s' direction='in'/>
340 ;; <arg type='o' direction='in'/>
341 ;; <arg type='s' direction='in'/>
342 ;; <arg type='o' direction='out'/>
344 ;; <method name='CancelDeviceCreation'>
345 ;; <arg type='s' direction='in'/>
347 ;; <method name='RemoveDevice'>
348 ;; <arg type='o' direction='in'/>
350 ;; <method name='FindDevice'>
351 ;; <arg type='s' direction='in'/>
352 ;; <arg type='o' direction='out'/>
354 ;; <method name='RegisterAgent'>
355 ;; <arg type='o' direction='in'/>
356 ;; <arg type='s' direction='in'/>
358 ;; <method name='UnregisterAgent'>
359 ;; <arg type='o' direction='in'/>
361 ;; <signal name='DeviceCreated'>
364 ;; <signal name='DeviceRemoved'>
367 ;; <signal name='DeviceFound'>
369 ;; <arg type='a{sv}'/>
371 ;; <signal name='PropertyChanged'>
375 ;; <signal name='DeviceDisappeared'>
381 (defcustom tramp-bluez-discover-devices-timeout 60
382 "Defines seconds since last bluetooth device discovery before rescanning.
383 A value of 0 would require an immediate discovery during hostname
384 completion, nil means to use always cached values for discovered
388 :type '(choice (const nil) integer))
390 (defvar tramp-bluez-discovery nil
391 "Indicator for a running bluetooth device discovery.
392 It keeps the timestamp of last discovery.")
394 (defvar tramp-bluez-devices nil
395 "Alist of detected bluetooth devices.
396 Every entry is a list (NAME ADDRESS).")
398 (defconst tramp-hal-service "org.freedesktop.Hal"
399 "The well known name of the HAL service.")
401 (defconst tramp-hal-path-manager "/org/freedesktop/Hal/Manager"
402 "The object path of the HAL daemon manager.")
404 (defconst tramp-hal-interface-manager "org.freedesktop.Hal.Manager"
405 "The manager interface of the HAL daemon.")
407 (defconst tramp-hal-interface-device "org.freedesktop.Hal.Device"
408 "The device interface of the HAL daemon.")
410 (defconst tramp-gvfs-file-attributes
412 "standard::display-name"
413 ;; We don't need this one. It is used as delimiter in case the
414 ;; display name contains spaces, which is hard to parse.
416 "standard::symlink-target"
429 "access::can-execute"
432 "GVFS file attributes.")
434 (defconst tramp-gvfs-file-attributes-with-gvfs-ls-regexp
435 (concat "[[:blank:]]"
436 (regexp-opt tramp-gvfs-file-attributes t)
437 "=\\([^[:blank:]]+\\)")
438 "Regexp to parse GVFS file attributes with `gvfs-ls'.")
440 (defconst tramp-gvfs-file-attributes-with-gvfs-info-regexp
441 (concat "^[[:blank:]]*"
442 (regexp-opt tramp-gvfs-file-attributes t)
443 ":[[:blank:]]+\\(.*\\)$")
444 "Regexp to parse GVFS file attributes with `gvfs-info'.")
447 ;; New handlers should be added here.
448 (defconst tramp-gvfs-file-name-handler-alist
449 '((access-file . ignore)
450 (add-name-to-file . tramp-gvfs-handle-copy-file)
451 ;; `byte-compiler-base-file-name' performed by default handler.
452 ;; `copy-directory' performed by default handler.
453 (copy-file . tramp-gvfs-handle-copy-file)
454 (delete-directory . tramp-gvfs-handle-delete-directory)
455 (delete-file . tramp-gvfs-handle-delete-file)
456 ;; `diff-latest-backup-file' performed by default handler.
457 (directory-file-name . tramp-handle-directory-file-name)
458 (directory-files . tramp-handle-directory-files)
459 (directory-files-and-attributes
460 . tramp-handle-directory-files-and-attributes)
461 (dired-compress-file . ignore)
462 (dired-uncache . tramp-handle-dired-uncache)
463 (expand-file-name . tramp-gvfs-handle-expand-file-name)
464 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
466 (file-attributes . tramp-gvfs-handle-file-attributes)
467 (file-directory-p . tramp-gvfs-handle-file-directory-p)
468 (file-equal-p . tramp-handle-file-equal-p)
469 (file-executable-p . tramp-gvfs-handle-file-executable-p)
470 (file-exists-p . tramp-handle-file-exists-p)
471 (file-in-directory-p . tramp-handle-file-in-directory-p)
472 (file-local-copy . tramp-gvfs-handle-file-local-copy)
473 (file-modes . tramp-handle-file-modes)
474 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
475 (file-name-as-directory . tramp-handle-file-name-as-directory)
476 (file-name-completion . tramp-handle-file-name-completion)
477 (file-name-directory . tramp-handle-file-name-directory)
478 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
479 ;; `file-name-sans-versions' performed by default handler.
480 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
481 (file-notify-add-watch . tramp-gvfs-handle-file-notify-add-watch)
482 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
483 (file-notify-valid-p . tramp-handle-file-notify-valid-p)
484 (file-ownership-preserved-p . ignore)
485 (file-readable-p . tramp-gvfs-handle-file-readable-p)
486 (file-regular-p . tramp-handle-file-regular-p)
487 (file-remote-p . tramp-handle-file-remote-p)
488 (file-selinux-context . ignore)
489 (file-symlink-p . tramp-handle-file-symlink-p)
490 ;; `file-truename' performed by default handler.
491 (file-writable-p . tramp-gvfs-handle-file-writable-p)
492 (find-backup-file-name . tramp-handle-find-backup-file-name)
493 ;; `find-file-noselect' performed by default handler.
494 ;; `get-file-buffer' performed by default handler.
495 (insert-directory . tramp-handle-insert-directory)
496 (insert-file-contents . tramp-handle-insert-file-contents)
497 (load . tramp-handle-load)
498 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
499 (make-directory . tramp-gvfs-handle-make-directory)
500 (make-directory-internal . ignore)
501 (make-symbolic-link . tramp-handle-make-symbolic-link)
502 (process-file . ignore)
503 (rename-file . tramp-gvfs-handle-rename-file)
504 (set-file-acl . ignore)
505 (set-file-modes . ignore)
506 (set-file-selinux-context . ignore)
507 (set-file-times . ignore)
508 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
509 (shell-command . ignore)
510 (start-file-process . ignore)
511 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
512 (unhandled-file-name-directory . ignore)
513 (vc-registered . ignore)
514 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
515 (write-region . tramp-gvfs-handle-write-region))
516 "Alist of handler functions for Tramp GVFS method.
517 Operations not mentioned here will be handled by the default Emacs primitives.")
519 ;; It must be a `defsubst' in order to push the whole code into
520 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
522 (defsubst tramp-gvfs-file-name-p (filename)
523 "Check if it's a filename handled by the GVFS daemon."
524 (and (tramp-tramp-file-p filename)
526 (tramp-file-name-method (tramp-dissect-file-name filename))))
527 (and (stringp method) (member method tramp-gvfs-methods)))))
530 (defun tramp-gvfs-file-name-handler (operation &rest args)
531 "Invoke the GVFS related OPERATION.
532 First arg specifies the OPERATION, second arg is a list of arguments to
533 pass to the OPERATION."
534 (unless tramp-gvfs-enabled
535 (tramp-user-error nil "Package `tramp-gvfs' not supported"))
536 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
538 (save-match-data (apply (cdr fn) args))
539 (tramp-run-real-handler operation args))))
541 ;; This might be moved to tramp.el. It shall be the first file name
544 (when (featurep 'dbusbind)
545 (add-to-list 'tramp-foreign-file-name-handler-alist
546 (cons 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler)))
549 ;; D-Bus helper function.
551 (defun tramp-gvfs-dbus-string-to-byte-array (string)
552 "Like `dbus-string-to-byte-array' but add trailing \\0 if needed."
553 (dbus-string-to-byte-array
554 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
555 (concat string (string 0)) string)))
557 (defun tramp-gvfs-dbus-byte-array-to-string (byte-array)
558 "Like `dbus-byte-array-to-string' but remove trailing \\0 if exists."
559 ;; The byte array could be a variant. Take care.
561 (if (and (consp byte-array) (atom (car byte-array)))
562 byte-array (car byte-array))))
563 (dbus-byte-array-to-string
564 (if (and (consp byte-array) (zerop (car (last byte-array))))
565 (butlast byte-array) byte-array))))
567 (defun tramp-gvfs-stringify-dbus-message (message)
568 "Convert a D-Bus message into readable UTF8 strings, used for traces."
570 ((and (consp message) (characterp (car message)))
571 (format "%S" (tramp-gvfs-dbus-byte-array-to-string message)))
573 (mapcar 'tramp-gvfs-stringify-dbus-message message))
575 (format "%S" message))
578 (defmacro with-tramp-dbus-call-method
579 (vec synchronous bus service path interface method &rest args)
580 "Apply a D-Bus call on bus BUS.
582 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
583 it is an asynchronous call, with `ignore' as callback function.
585 The other arguments have the same meaning as with `dbus-call-method'
586 or `dbus-call-method-asynchronously'. Additionally, the call
587 will be traced by Tramp with trace level 6."
588 `(let ((func (if ,synchronous
589 'dbus-call-method 'dbus-call-method-asynchronously))
590 (args (append (list ,bus ,service ,path ,interface ,method)
591 (if ,synchronous (list ,@args) (list 'ignore ,@args))))
593 (tramp-message ,vec 6 "%s %s" func args)
594 (setq result (apply func args))
595 (tramp-message ,vec 6 "%s" (tramp-gvfs-stringify-dbus-message result))
598 (put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
599 (put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
600 (font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
602 (defvar tramp-gvfs-dbus-event-vector nil
603 "Current Tramp file name to be used, as vector.
604 It is needed when D-Bus signals or errors arrive, because there
605 is no information where to trace the message.")
607 (defun tramp-gvfs-dbus-event-error (event err)
608 "Called when a D-Bus error message arrives, see `dbus-event-error-functions'."
609 (when tramp-gvfs-dbus-event-vector
610 (tramp-message tramp-gvfs-dbus-event-vector 10 "%S" event)
611 (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err))))
613 ;; `dbus-event-error-hooks' has been renamed to `dbus-event-error-functions'.
615 (if (boundp 'dbus-event-error-functions)
616 'dbus-event-error-functions 'dbus-event-error-hooks)
617 'tramp-gvfs-dbus-event-error)
620 ;; File name primitives.
622 (defun tramp-gvfs-do-copy-or-rename-file
623 (op filename newname &optional ok-if-already-exists keep-date
624 preserve-uid-gid preserve-extended-attributes)
625 "Copy or rename a remote file.
626 OP must be `copy' or `rename' and indicates the operation to perform.
627 FILENAME specifies the file to copy or rename, NEWNAME is the name of
628 the new file (for copy) or the new name of the file (for rename).
629 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
630 KEEP-DATE means to make sure that NEWNAME has the same timestamp
631 as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
632 the uid and gid if both files are on the same host.
633 PRESERVE-EXTENDED-ATTRIBUTES is ignored.
635 This function is invoked by `tramp-gvfs-handle-copy-file' and
636 `tramp-gvfs-handle-rename-file'. It is an error if OP is neither
637 of `copy' and `rename'. FILENAME and NEWNAME must be absolute
639 (unless (memq op '(copy rename))
640 (error "Unknown operation `%s', must be `copy' or `rename'" op))
642 (let ((t1 (tramp-tramp-file-p filename))
643 (t2 (tramp-tramp-file-p newname))
644 (equal-remote (tramp-equal-remote filename newname))
645 (file-operation (intern (format "%s-file" op)))
646 (gvfs-operation (if (eq op 'copy) "gvfs-copy" "gvfs-move"))
647 (msg-operation (if (eq op 'copy) "Copying" "Renaming")))
649 (with-parsed-tramp-file-name (if t1 filename newname) nil
650 (when (and (not ok-if-already-exists) (file-exists-p newname))
652 v 'file-already-exists "File %s already exists" newname))
654 (if (or (and equal-remote
655 (tramp-get-connection-property v "direct-copy-failed" nil))
656 (and t1 (not (tramp-gvfs-file-name-p filename)))
657 (and t2 (not (tramp-gvfs-file-name-p newname))))
659 ;; We cannot copy or rename directly.
660 ;; PRESERVE-EXTENDED-ATTRIBUTES has been introduced with
661 ;; Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and renamed
663 (let ((tmpfile (tramp-compat-make-temp-file filename)))
665 (preserve-extended-attributes
668 filename tmpfile t keep-date preserve-uid-gid
669 preserve-extended-attributes))
672 file-operation filename tmpfile t keep-date preserve-uid-gid)))
673 (rename-file tmpfile newname ok-if-already-exists))
676 (with-tramp-progress-reporter
677 v 0 (format "%s %s to %s" msg-operation filename newname)
680 'tramp-gvfs-send-command v gvfs-operation
682 (and (eq op 'copy) (or keep-date preserve-uid-gid)
685 (tramp-gvfs-url-file-name filename)
686 (tramp-gvfs-url-file-name newname))))
688 (if (or (not equal-remote)
690 (tramp-get-connection-property
691 v "direct-copy-failed" nil)))
692 ;; Propagate the error.
693 (with-current-buffer (tramp-get-connection-buffer v)
694 (goto-char (point-min))
695 (tramp-error-with-buffer
697 "%s failed, see buffer `%s' for details."
698 msg-operation (buffer-name)))
700 ;; Some WebDAV server, like the one from QNAP, do not
701 ;; support direct copy/move. Try a fallback.
702 (tramp-set-connection-property v "direct-copy-failed" t)
703 (tramp-gvfs-do-copy-or-rename-file
704 op filename newname ok-if-already-exists keep-date
705 preserve-uid-gid preserve-extended-attributes))))
707 (when (and t1 (eq op 'rename))
708 (with-parsed-tramp-file-name filename nil
709 (tramp-flush-file-property v (file-name-directory localname))
710 (tramp-flush-file-property v localname)))
713 (with-parsed-tramp-file-name newname nil
714 (tramp-flush-file-property v (file-name-directory localname))
715 (tramp-flush-file-property v localname)))))))
717 (defun tramp-gvfs-handle-copy-file
718 (filename newname &optional ok-if-already-exists keep-date
719 preserve-uid-gid preserve-extended-attributes)
720 "Like `copy-file' for Tramp files."
721 (setq filename (expand-file-name filename))
722 (setq newname (expand-file-name newname))
724 ;; At least one file a Tramp file?
725 ((or (tramp-tramp-file-p filename)
726 (tramp-tramp-file-p newname))
727 (tramp-gvfs-do-copy-or-rename-file
728 'copy filename newname ok-if-already-exists keep-date
729 preserve-uid-gid preserve-extended-attributes))
730 ;; Compat section. PRESERVE-EXTENDED-ATTRIBUTES has been
731 ;; introduced with Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and
732 ;; renamed in Emacs 24.3.
733 (preserve-extended-attributes
734 (tramp-run-real-handler
736 (list filename newname ok-if-already-exists keep-date
737 preserve-uid-gid preserve-extended-attributes)))
739 (tramp-run-real-handler
741 (list filename newname ok-if-already-exists keep-date preserve-uid-gid)))))
743 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash)
744 "Like `delete-directory' for Tramp files."
745 (when (and recursive (not (file-symlink-p directory)))
747 (if (eq t (car (file-attributes file)))
748 (tramp-compat-delete-directory file recursive trash)
749 (tramp-compat-delete-file file trash)))
751 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
752 (with-parsed-tramp-file-name directory nil
753 (tramp-flush-file-property v (file-name-directory localname))
754 (tramp-flush-directory-property v localname)
756 (tramp-gvfs-send-command
757 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
758 (tramp-gvfs-url-file-name directory))
759 ;; Propagate the error.
760 (with-current-buffer (tramp-get-connection-buffer v)
761 (goto-char (point-min))
762 (tramp-error-with-buffer
763 nil v 'file-error "Couldn't delete %s" directory)))))
765 (defun tramp-gvfs-handle-delete-file (filename &optional trash)
766 "Like `delete-file' for Tramp files."
767 (with-parsed-tramp-file-name filename nil
768 (tramp-flush-file-property v (file-name-directory localname))
769 (tramp-flush-file-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 filename))
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" filename)))))
780 (defun tramp-gvfs-handle-expand-file-name (name &optional dir)
781 "Like `expand-file-name' for Tramp files."
782 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
783 (setq dir (or dir default-directory "/"))
784 ;; Unless NAME is absolute, concat DIR and NAME.
785 (unless (file-name-absolute-p name)
786 (setq name (concat (file-name-as-directory dir) name)))
787 ;; If NAME is not a Tramp file, run the real handler.
788 (if (not (tramp-tramp-file-p name))
789 (tramp-run-real-handler 'expand-file-name (list name nil))
791 (with-parsed-tramp-file-name name nil
792 ;; If there is a default location, expand tilde.
793 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname)
795 (tramp-gvfs-maybe-open-connection (vector method user host "/" hop)))
798 (tramp-get-file-property v "/" "default-location" "~")
800 ;; Tilde expansion is not possible.
801 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
804 "Cannot expand tilde in file `%s'" name))
805 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
806 (setq localname (concat "/" localname)))
807 ;; We do not pass "/..".
808 (if (string-match "^\\(afp\\|smb\\)$" method)
809 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
810 (setq localname (replace-match "/" t t localname 1)))
811 (when (string-match "^/\\.\\./?" localname)
812 (setq localname (replace-match "/" t t localname))))
813 ;; There might be a double slash. Remove this.
814 (while (string-match "//" localname)
815 (setq localname (replace-match "/" t t localname)))
816 ;; No tilde characters in file name, do normal
817 ;; `expand-file-name' (this does "/./" and "/../").
818 (tramp-make-tramp-file-name
820 (tramp-run-real-handler
821 'expand-file-name (list localname))))))
823 (defun tramp-gvfs-get-directory-attributes (directory)
824 "Return GVFS attributes association list of all files in DIRECTORY."
826 ;; Don't modify `last-coding-system-used' by accident.
827 (let ((last-coding-system-used last-coding-system-used)
829 (with-parsed-tramp-file-name directory nil
830 (with-tramp-file-property v localname "directory-gvfs-attributes"
831 (tramp-message v 5 "directory gvfs attributes: %s" localname)
833 (tramp-gvfs-send-command
834 v "gvfs-ls" "-h" "-n" "-a"
835 (mapconcat 'identity tramp-gvfs-file-attributes ",")
836 (tramp-gvfs-url-file-name directory))
838 (with-current-buffer (tramp-get-connection-buffer v)
839 (goto-char (point-min))
840 (while (re-search-forward
841 (concat "^\\(.+\\)[[:blank:]]"
842 "\\([[:digit:]]+\\)[[:blank:]]"
843 "(\\(.+\\))[[:blank:]]"
844 "standard::display-name=\\(.+\\)[[:blank:]]"
847 (let ((item (list (cons "standard::display-name" (match-string 4))
848 (cons "type" (match-string 3))
849 (cons "standard::size" (match-string 2))
851 (while (re-search-forward
852 tramp-gvfs-file-attributes-with-gvfs-ls-regexp
854 (push (cons (match-string 1) (match-string 2)) item))
855 (push (nreverse item) result))
859 (defun tramp-gvfs-get-root-attributes (filename)
860 "Return GVFS attributes association list of FILENAME."
862 ;; Don't modify `last-coding-system-used' by accident.
863 (let ((last-coding-system-used last-coding-system-used)
865 (with-parsed-tramp-file-name filename nil
866 (with-tramp-file-property v localname "file-gvfs-attributes"
867 (tramp-message v 5 "file gvfs attributes: %s" localname)
869 (tramp-gvfs-send-command
870 v "gvfs-info" (tramp-gvfs-url-file-name filename))
872 (with-current-buffer (tramp-get-connection-buffer v)
873 (goto-char (point-min))
874 (while (re-search-forward
875 tramp-gvfs-file-attributes-with-gvfs-info-regexp nil t)
876 (push (cons (match-string 1) (match-string 2)) result))
879 (defun tramp-gvfs-get-file-attributes (filename)
880 "Return GVFS attributes association list of FILENAME."
881 (setq filename (directory-file-name (expand-file-name filename)))
882 (with-parsed-tramp-file-name filename nil
884 (and (string-match "^\\(afp\\|smb\\)$" method)
885 (string-match "^/?\\([^/]+\\)$" localname))
886 (string-equal localname "/"))
887 (tramp-gvfs-get-root-attributes filename)
889 (file-name-nondirectory filename)
890 (tramp-gvfs-get-directory-attributes (file-name-directory filename))))))
892 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
893 "Like `file-attributes' for Tramp files."
894 (unless id-format (setq id-format 'integer))
896 (let ((attributes (tramp-gvfs-get-file-attributes filename))
897 dirp res-symlink-target res-numlinks res-uid res-gid res-access
898 res-mod res-change res-size res-filemodes res-inode res-device)
900 ;; ... directory or symlink
901 (setq dirp (if (equal "directory" (cdr (assoc "type" attributes))) t))
902 (setq res-symlink-target
903 (cdr (assoc "standard::symlink-target" attributes)))
907 (or (cdr (assoc "unix::nlink" attributes)) "0")))
910 (if (eq id-format 'integer)
912 (or (cdr (assoc "unix::uid" attributes))
913 (format "%s" tramp-unknown-id-integer)))
914 (or (cdr (assoc "owner::user" attributes))
915 (cdr (assoc "unix::uid" attributes))
916 tramp-unknown-id-string)))
918 (if (eq id-format 'integer)
920 (or (cdr (assoc "unix::gid" attributes))
921 (format "%s" tramp-unknown-id-integer)))
922 (or (cdr (assoc "owner::group" attributes))
923 (cdr (assoc "unix::gid" attributes))
924 tramp-unknown-id-string)))
925 ;; ... last access, modification and change time
929 (or (cdr (assoc "time::access" attributes)) "0"))))
933 (or (cdr (assoc "time::modified" attributes)) "0"))))
937 (or (cdr (assoc "time::changed" attributes)) "0"))))
941 (or (cdr (assoc "standard::size" attributes)) "0")))
942 ;; ... file mode flags
944 (let ((n (cdr (assoc "unix::mode" attributes))))
946 (tramp-file-mode-from-int (string-to-number n))
950 (if (equal (cdr (assoc "access::can-read" attributes))
953 (if (equal (cdr (assoc "access::can-write" attributes))
956 (if (equal (cdr (assoc "access::can-execute" attributes))
959 ;; ... inode and device
961 (let ((n (cdr (assoc "unix::inode" attributes))))
964 (tramp-get-inode (tramp-dissect-file-name filename)))))
966 (let ((n (cdr (assoc "unix::device" attributes))))
969 (tramp-get-device (tramp-dissect-file-name filename)))))
971 ;; Return data gathered.
973 ;; 0. t for directory, string (name linked to) for
974 ;; symbolic link, or nil.
975 (or dirp res-symlink-target)
976 ;; 1. Number of links to file.
982 ;; 4. Last access time, as a list of integers.
983 ;; 5. Last modification time, likewise.
984 ;; 6. Last status change time, likewise.
985 res-access res-mod res-change
986 ;; 7. Size in bytes (-1, if number is out of range).
990 ;; 9. t if file's gid would change if file were deleted
995 ;; 11. Device number.
999 (defun tramp-gvfs-handle-file-directory-p (filename)
1000 "Like `file-directory-p' for Tramp files."
1001 (eq t (car (file-attributes (file-truename filename)))))
1003 (defun tramp-gvfs-handle-file-executable-p (filename)
1004 "Like `file-executable-p' for Tramp files."
1005 (with-parsed-tramp-file-name filename nil
1006 (with-tramp-file-property v localname "file-executable-p"
1007 (tramp-check-cached-permissions v ?x))))
1009 (defun tramp-gvfs-handle-file-local-copy (filename)
1010 "Like `file-local-copy' for Tramp files."
1011 (with-parsed-tramp-file-name filename nil
1012 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1013 (unless (file-exists-p filename)
1016 "Cannot make local copy of non-existing file `%s'" filename))
1017 (copy-file filename tmpfile 'ok-if-already-exists 'keep-time)
1020 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
1021 "Like `file-name-all-completions' for Tramp files."
1022 (unless (save-match-data (string-match "/" filename))
1025 (with-parsed-tramp-file-name (expand-file-name directory) nil
1026 (with-tramp-file-property v localname "file-name-all-completions"
1027 (let ((result '("./" "../"))
1029 ;; Get a list of directories and files.
1030 (dolist (item (tramp-gvfs-get-directory-attributes directory) result)
1032 (or ;; Use display-name if available (google-drive).
1033 ;(cdr (assoc "standard::display-name" item))
1035 (if (string-equal (cdr (assoc "type" item)) "directory")
1036 (push (file-name-as-directory entry) result)
1037 (push entry result)))))))))
1039 (defun tramp-gvfs-handle-file-notify-add-watch (file-name flags _callback)
1040 "Like `file-notify-add-watch' for Tramp files."
1041 (setq file-name (expand-file-name file-name))
1042 (with-parsed-tramp-file-name file-name nil
1043 ;; We cannot watch directories, because `gvfs-monitor-dir' is not
1044 ;; supported for gvfs-mounted directories.
1045 (when (file-directory-p file-name)
1047 v 'file-notify-error "Monitoring not supported for `%s'" file-name))
1048 (let* ((default-directory (file-name-directory file-name))
1051 ((and (memq 'change flags) (memq 'attribute-change flags))
1052 '(created changed changes-done-hint moved deleted
1054 ((memq 'change flags)
1055 '(created changed changes-done-hint moved deleted))
1056 ((memq 'attribute-change flags) '(attribute-changed))))
1058 "gvfs-monitor-file" (generate-new-buffer " *gvfs-monitor-file*")
1059 "gvfs-monitor-file" (tramp-gvfs-url-file-name file-name))))
1060 (if (not (processp p))
1062 v 'file-notify-error "Monitoring not supported for `%s'" file-name)
1064 v 6 "Run `%s', %S" (mapconcat 'identity (process-command p) " ") p)
1065 (tramp-set-connection-property p "vector" v)
1066 (process-put p 'events events)
1067 (process-put p 'watch-name localname)
1068 (set-process-query-on-exit-flag p nil)
1069 (set-process-filter p 'tramp-gvfs-monitor-file-process-filter)
1070 ;; There might be an error if the monitor is not supported.
1071 ;; Give the filter a chance to read the output.
1072 (tramp-accept-process-output p 1)
1073 (unless (memq (process-status p) '(run open))
1075 v 'file-notify-error "Monitoring not supported for `%s'" file-name))
1078 (defun tramp-gvfs-monitor-file-process-filter (proc string)
1079 "Read output from \"gvfs-monitor-file\" and add corresponding \
1080 file-notify events."
1081 (let* ((rest-string (process-get proc 'rest-string))
1082 (dd (with-current-buffer (process-buffer proc) default-directory))
1083 (ddu (regexp-quote (tramp-gvfs-url-file-name dd))))
1085 (tramp-message proc 10 "Previous string:\n%s" rest-string))
1086 (tramp-message proc 6 "%S\n%s" proc string)
1087 (setq string (concat rest-string string)
1088 ;; Attribute change is returned in unused wording.
1089 string (replace-regexp-in-string
1090 "ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string))
1091 (when (string-match "Monitoring not supported" string)
1092 (delete-process proc))
1094 (while (string-match
1096 "File Monitor Event:[\n\r]+"
1097 "File = \\([^\n\r]+\\)[\n\r]+"
1098 "Event = \\([^[:blank:]]+\\)[\n\r]+")
1100 (let ((file (match-string 1 string))
1101 (action (intern-soft
1102 (replace-regexp-in-string
1103 "_" "-" (downcase (match-string 2 string))))))
1104 (setq string (replace-match "" nil nil string))
1105 ;; File names are returned as URL paths. We must convert them.
1106 (when (string-match ddu file)
1107 (setq file (replace-match dd nil nil file)))
1108 (while (string-match "%\\([0-9A-F]\\{2\\}\\)" file)
1111 (char-to-string (string-to-number (match-string 1 file) 16))
1113 ;; Usually, we would add an Emacs event now. Unfortunately,
1114 ;; `unread-command-events' does not accept several events at
1115 ;; once. Therefore, we apply the callback directly.
1116 (tramp-compat-funcall 'file-notify-callback (list proc action file))))
1118 ;; Save rest of the string.
1119 (when (zerop (length string)) (setq string nil))
1120 (when string (tramp-message proc 10 "Rest string:\n%s" string))
1121 (process-put proc 'rest-string string)))
1123 (defun tramp-gvfs-handle-file-readable-p (filename)
1124 "Like `file-readable-p' for Tramp files."
1125 (with-parsed-tramp-file-name filename nil
1126 (with-tramp-file-property v localname "file-readable-p"
1127 (tramp-check-cached-permissions v ?r))))
1129 (defun tramp-gvfs-handle-file-writable-p (filename)
1130 "Like `file-writable-p' for Tramp files."
1131 (with-parsed-tramp-file-name filename nil
1132 (with-tramp-file-property v localname "file-writable-p"
1133 (if (file-exists-p filename)
1134 (tramp-check-cached-permissions v ?w)
1135 ;; If file doesn't exist, check if directory is writable.
1136 (and (file-directory-p (file-name-directory filename))
1137 (file-writable-p (file-name-directory filename)))))))
1139 (defun tramp-gvfs-handle-make-directory (dir &optional parents)
1140 "Like `make-directory' for Tramp files."
1141 (setq dir (directory-file-name (expand-file-name dir)))
1142 (with-parsed-tramp-file-name dir nil
1143 (tramp-flush-file-property v (file-name-directory localname))
1144 (tramp-flush-directory-property v localname)
1146 (let ((ldir (file-name-directory dir)))
1147 ;; Make missing directory parts. "gvfs-mkdir -p ..." does not
1149 (when (and parents (not (file-directory-p ldir)))
1150 (make-directory ldir parents))
1152 (unless (tramp-gvfs-send-command
1153 v "gvfs-mkdir" (tramp-gvfs-url-file-name dir))
1154 (tramp-error v 'file-error "Couldn't make directory %s" dir))))))
1156 (defun tramp-gvfs-handle-rename-file
1157 (filename newname &optional ok-if-already-exists)
1158 "Like `rename-file' for Tramp files."
1159 ;; Check if both files are local -- invoke normal rename-file.
1160 ;; Otherwise, use Tramp from local system.
1161 (setq filename (expand-file-name filename))
1162 (setq newname (expand-file-name newname))
1163 ;; At least one file a Tramp file?
1164 (if (or (tramp-tramp-file-p filename)
1165 (tramp-tramp-file-p newname))
1166 (tramp-gvfs-do-copy-or-rename-file
1167 'rename filename newname ok-if-already-exists
1168 'keep-date 'preserve-uid-gid)
1169 (tramp-run-real-handler
1170 'rename-file (list filename newname ok-if-already-exists))))
1172 (defun tramp-gvfs-handle-write-region
1173 (start end filename &optional append visit lockname confirm)
1174 "Like `write-region' for Tramp files."
1175 (with-parsed-tramp-file-name filename nil
1176 (when (and confirm (file-exists-p filename))
1177 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
1178 (tramp-error v 'file-error "File not overwritten")))
1180 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1181 (when (and append (file-exists-p filename))
1182 (copy-file filename tmpfile 'ok))
1183 ;; We say `no-message' here because we don't want the visited file
1184 ;; modtime data to be clobbered from the temp file. We call
1185 ;; `set-visited-file-modtime' ourselves later on.
1186 (tramp-run-real-handler
1188 (if confirm ; don't pass this arg unless defined for backward compat.
1189 (list start end tmpfile append 'no-message lockname confirm)
1190 (list start end tmpfile append 'no-message lockname)))
1192 (rename-file tmpfile filename 'ok-if-already-exists)
1194 (delete-file tmpfile)
1196 v 'file-error "Couldn't write region to `%s'" filename))))
1198 (tramp-flush-file-property v (file-name-directory localname))
1199 (tramp-flush-file-property v localname)
1201 ;; Set file modification time.
1202 (when (or (eq visit t) (stringp visit))
1203 (set-visited-file-modtime (nth 5 (file-attributes filename))))
1206 (when (or (eq visit t) (null visit) (stringp visit))
1207 (tramp-message v 0 "Wrote %s" filename))
1208 (run-hooks 'tramp-handle-write-region-hook)))
1211 ;; File name conversions.
1213 (defun tramp-gvfs-url-file-name (filename)
1214 "Return FILENAME in URL syntax."
1215 ;; "/" must NOT be hexlified.
1216 (let ((url-unreserved-chars (cons ?/ url-unreserved-chars))
1221 (if (tramp-tramp-file-p filename)
1222 (with-parsed-tramp-file-name filename nil
1223 (when (and user (string-match tramp-user-with-domain-regexp user))
1225 (concat (match-string 2 user) ";" (match-string 1 user))))
1226 (url-parse-make-urlobj
1227 method (and user (url-hexify-string user)) nil
1228 (tramp-file-name-real-host v) (tramp-file-name-port v)
1229 (and localname (url-hexify-string localname)) nil nil t))
1230 (url-parse-make-urlobj
1231 "file" nil nil nil nil
1232 (url-hexify-string (file-truename filename)) nil nil t))))
1233 (when (tramp-tramp-file-p filename)
1234 (with-parsed-tramp-file-name filename nil
1235 (tramp-message v 10 "remote file `%s' is URL `%s'" filename result)))
1238 (defun tramp-gvfs-object-path (filename)
1239 "Create a D-Bus object path from FILENAME."
1240 (expand-file-name (dbus-escape-as-identifier filename) tramp-gvfs-path-tramp))
1242 (defun tramp-gvfs-file-name (object-path)
1243 "Retrieve file name from D-Bus OBJECT-PATH."
1244 (dbus-unescape-from-identifier
1245 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
1247 (defun tramp-bluez-address (device)
1248 "Return bluetooth device address from a given bluetooth DEVICE name."
1249 (when (stringp device)
1250 (if (string-match tramp-ipv6-regexp device)
1251 (match-string 0 device)
1252 (cadr (assoc device (tramp-bluez-list-devices))))))
1254 (defun tramp-bluez-device (address)
1255 "Return bluetooth device name from a given bluetooth device ADDRESS.
1256 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
1257 (when (stringp address)
1258 (while (string-match "[][]" address)
1259 (setq address (replace-match "" t t address)))
1261 (dolist (item (tramp-bluez-list-devices) result)
1262 (when (string-match address (cadr item))
1263 (setq result (car item)))))))
1266 ;; D-Bus GVFS functions.
1268 (defun tramp-gvfs-handler-askpassword (message user domain flags)
1269 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
1271 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)))
1275 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message)
1276 (capitalize (match-string 1 message))
1282 (with-parsed-tramp-file-name filename l
1283 (when (and (zerop (length user))
1285 (zerop (logand flags tramp-gvfs-password-need-username))))
1286 (setq user (read-string "User name: ")))
1287 (when (and (zerop (length domain))
1289 (zerop (logand flags tramp-gvfs-password-need-domain))))
1290 (setq domain (read-string "Domain name: ")))
1292 (tramp-message l 6 "%S %S %S %d" message user domain flags)
1293 (unless (tramp-get-connection-property l "first-password-request" nil)
1294 (tramp-clear-passwd l))
1296 (setq tramp-current-method l-method
1297 tramp-current-user user
1298 tramp-current-host l-host
1299 password (tramp-read-passwd
1300 (tramp-get-connection-process l) pw-prompt))
1303 (if (stringp password)
1305 t ;; password handled.
1306 nil ;; no abort of D-Bus.
1308 (tramp-file-name-real-user l)
1310 nil ;; not anonymous.
1311 0) ;; no password save.
1312 ;; No password provided.
1313 (list nil t "" (tramp-file-name-real-user l) domain nil 0)))
1315 ;; When QUIT is raised, we shall return this information to D-Bus.
1316 (quit (list nil t "" "" "" nil 0)))))
1318 (defun tramp-gvfs-handler-askquestion (message choices)
1319 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
1320 (save-window-excursion
1321 (let ((enable-recursive-minibuffers t)
1325 (with-parsed-tramp-file-name
1326 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)) nil
1327 (tramp-message v 6 "%S %S" message choices)
1329 ;; In theory, there can be several choices. Until now,
1330 ;; there is only the question whether to accept an unknown
1333 ;; Preserve message for `progress-reporter'.
1334 (with-temp-message ""
1336 (pop-to-buffer (current-buffer))
1337 (setq choice (if (yes-or-no-p (concat (car choices) " ")) 0 1))
1338 (tramp-message v 6 "%d" choice)))
1340 ;; When the choice is "no", we set a dummy fuse-mountpoint
1341 ;; in order to leave the timeout.
1342 (unless (zerop choice)
1343 (tramp-set-file-property v "/" "fuse-mountpoint" "/"))
1347 nil ;; no abort of D-Bus.
1350 ;; When QUIT is raised, we shall return this information to D-Bus.
1351 (quit (list nil t 0))))))
1353 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
1354 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
1355 \"org.gtk.vfs.MountTracker.unmounted\" signals."
1357 (let ((signal-name (dbus-event-member-name last-input-event))
1359 ;; Jump over the first elements of the mount info. Since there
1360 ;; were changes in the entries, we cannot access dedicated
1362 (while (stringp (car elt)) (setq elt (cdr elt)))
1363 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string (cadr elt)))
1364 (mount-spec (caddr elt))
1365 (default-location (tramp-gvfs-dbus-byte-array-to-string
1367 (method (tramp-gvfs-dbus-byte-array-to-string
1368 (cadr (assoc "type" (cadr mount-spec)))))
1369 (user (tramp-gvfs-dbus-byte-array-to-string
1370 (cadr (assoc "user" (cadr mount-spec)))))
1371 (domain (tramp-gvfs-dbus-byte-array-to-string
1372 (cadr (assoc "domain" (cadr mount-spec)))))
1373 (host (tramp-gvfs-dbus-byte-array-to-string
1374 (cadr (or (assoc "host" (cadr mount-spec))
1375 (assoc "server" (cadr mount-spec))))))
1376 (port (tramp-gvfs-dbus-byte-array-to-string
1377 (cadr (assoc "port" (cadr mount-spec)))))
1378 (ssl (tramp-gvfs-dbus-byte-array-to-string
1379 (cadr (assoc "ssl" (cadr mount-spec)))))
1381 (tramp-gvfs-dbus-byte-array-to-string
1383 (tramp-gvfs-dbus-byte-array-to-string
1384 (or (cadr (assoc "share" (cadr mount-spec)))
1385 (cadr (assoc "volume" (cadr mount-spec))))))))
1386 (when (string-match "^\\(afp\\|smb\\)" method)
1387 (setq method (match-string 1 method)))
1388 (when (string-equal "obex" method)
1389 (setq host (tramp-bluez-device host)))
1390 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1391 (setq method "davs"))
1392 (unless (zerop (length domain))
1393 (setq user (concat user tramp-prefix-domain-format domain)))
1394 (unless (zerop (length port))
1395 (setq host (concat host tramp-prefix-port-format port)))
1396 (with-parsed-tramp-file-name
1397 (tramp-make-tramp-file-name method user host "") nil
1400 signal-name (tramp-gvfs-stringify-dbus-message mount-info))
1401 (tramp-set-file-property v "/" "list-mounts" 'undef)
1402 (if (string-equal (downcase signal-name) "unmounted")
1403 (tramp-set-file-property v "/" "fuse-mountpoint" nil)
1404 ;; Set prefix, mountpoint and location.
1405 (unless (string-equal prefix "/")
1406 (tramp-set-file-property v "/" "prefix" prefix))
1407 (tramp-set-file-property v "/" "fuse-mountpoint" fuse-mountpoint)
1408 (tramp-set-file-property
1409 v "/" "default-location" default-location)))))))
1411 (when tramp-gvfs-enabled
1412 (dbus-register-signal
1413 :session nil tramp-gvfs-path-mounttracker
1414 tramp-gvfs-interface-mounttracker "mounted"
1415 'tramp-gvfs-handler-mounted-unmounted)
1416 (dbus-register-signal
1417 :session nil tramp-gvfs-path-mounttracker
1418 tramp-gvfs-interface-mounttracker "Mounted"
1419 'tramp-gvfs-handler-mounted-unmounted)
1421 (dbus-register-signal
1422 :session nil tramp-gvfs-path-mounttracker
1423 tramp-gvfs-interface-mounttracker "unmounted"
1424 'tramp-gvfs-handler-mounted-unmounted)
1425 (dbus-register-signal
1426 :session nil tramp-gvfs-path-mounttracker
1427 tramp-gvfs-interface-mounttracker "Unmounted"
1428 'tramp-gvfs-handler-mounted-unmounted))
1430 (defun tramp-gvfs-connection-mounted-p (vec)
1431 "Check, whether the location is already mounted."
1433 (tramp-get-file-property vec "/" "fuse-mountpoint" nil)
1437 (with-tramp-file-property vec "/" "list-mounts"
1438 (with-tramp-dbus-call-method vec t
1439 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1440 tramp-gvfs-interface-mounttracker tramp-gvfs-listmounts))
1442 ;; Jump over the first elements of the mount info. Since there
1443 ;; were changes in the entries, we cannot access dedicated
1445 (while (stringp (car elt)) (setq elt (cdr elt)))
1446 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string
1448 (mount-spec (caddr elt))
1449 (default-location (tramp-gvfs-dbus-byte-array-to-string
1451 (method (tramp-gvfs-dbus-byte-array-to-string
1452 (cadr (assoc "type" (cadr mount-spec)))))
1453 (user (tramp-gvfs-dbus-byte-array-to-string
1454 (cadr (assoc "user" (cadr mount-spec)))))
1455 (domain (tramp-gvfs-dbus-byte-array-to-string
1456 (cadr (assoc "domain" (cadr mount-spec)))))
1457 (host (tramp-gvfs-dbus-byte-array-to-string
1458 (cadr (or (assoc "host" (cadr mount-spec))
1459 (assoc "server" (cadr mount-spec))))))
1460 (port (tramp-gvfs-dbus-byte-array-to-string
1461 (cadr (assoc "port" (cadr mount-spec)))))
1462 (ssl (tramp-gvfs-dbus-byte-array-to-string
1463 (cadr (assoc "ssl" (cadr mount-spec)))))
1465 (tramp-gvfs-dbus-byte-array-to-string
1467 (tramp-gvfs-dbus-byte-array-to-string
1469 (cadr (assoc "share" (cadr mount-spec)))
1470 (cadr (assoc "volume" (cadr mount-spec))))))))
1471 (when (string-match "^\\(afp\\|smb\\)" method)
1472 (setq method (match-string 1 method)))
1473 (when (string-equal "obex" method)
1474 (setq host (tramp-bluez-device host)))
1475 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1476 (setq method "davs"))
1477 (when (and (string-equal "synce" method) (zerop (length user)))
1478 (setq user (or (tramp-file-name-user vec) "")))
1479 (unless (zerop (length domain))
1480 (setq user (concat user tramp-prefix-domain-format domain)))
1481 (unless (zerop (length port))
1482 (setq host (concat host tramp-prefix-port-format port)))
1484 (string-equal method (tramp-file-name-method vec))
1485 (string-equal user (or (tramp-file-name-user vec) ""))
1486 (string-equal host (tramp-file-name-host vec))
1487 (string-match (concat "^" (regexp-quote prefix))
1488 (tramp-file-name-localname vec)))
1489 ;; Set prefix, mountpoint and location.
1490 (unless (string-equal prefix "/")
1491 (tramp-set-file-property vec "/" "prefix" prefix))
1492 (tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
1493 (tramp-set-file-property vec "/" "default-location" default-location)
1494 (throw 'mounted t)))))))
1496 (defun tramp-gvfs-mount-spec-entry (key value)
1497 "Construct a mount-spec entry to be used in a mount_spec.
1498 It was \"a(say)\", but has changed to \"a{sv})\"."
1499 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
1500 (list :dict-entry key
1501 (list :variant (tramp-gvfs-dbus-string-to-byte-array value)))
1502 (list :struct key (tramp-gvfs-dbus-string-to-byte-array value))))
1504 (defun tramp-gvfs-mount-spec (vec)
1505 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1506 (let* ((method (tramp-file-name-method vec))
1507 (user (tramp-file-name-real-user vec))
1508 (domain (tramp-file-name-domain vec))
1509 (host (tramp-file-name-real-host vec))
1510 (port (tramp-file-name-port vec))
1511 (localname (tramp-file-name-localname vec))
1512 (share (when (string-match "^/?\\([^/]+\\)" localname)
1513 (match-string 1 localname)))
1514 (ssl (when (string-match "^davs" method) "true" "false"))
1518 ((string-equal "smb" method)
1519 (list (tramp-gvfs-mount-spec-entry "type" "smb-share")
1520 (tramp-gvfs-mount-spec-entry "server" host)
1521 (tramp-gvfs-mount-spec-entry "share" share)))
1522 ((string-equal "obex" method)
1523 (list (tramp-gvfs-mount-spec-entry "type" method)
1524 (tramp-gvfs-mount-spec-entry
1525 "host" (concat "[" (tramp-bluez-address host) "]"))))
1526 ((string-match "\\`dav" method)
1527 (list (tramp-gvfs-mount-spec-entry "type" "dav")
1528 (tramp-gvfs-mount-spec-entry "host" host)
1529 (tramp-gvfs-mount-spec-entry "ssl" ssl)))
1530 ((string-equal "afp" method)
1531 (list (tramp-gvfs-mount-spec-entry "type" "afp-volume")
1532 (tramp-gvfs-mount-spec-entry "host" host)
1533 (tramp-gvfs-mount-spec-entry "volume" share)))
1535 (list (tramp-gvfs-mount-spec-entry "type" method)
1536 (tramp-gvfs-mount-spec-entry "host" host))))
1538 (list (tramp-gvfs-mount-spec-entry "user" user)))
1540 (list (tramp-gvfs-mount-spec-entry "domain" domain)))
1542 (list (tramp-gvfs-mount-spec-entry
1543 "port" (number-to-string port))))))
1545 (if (and (string-match "\\`dav" method)
1546 (string-match "^/?[^/]+" localname))
1547 (match-string 0 localname)
1551 `(:struct ,(tramp-gvfs-dbus-string-to-byte-array mount-pref) ,mount-spec)))
1554 ;; Connection functions.
1556 (defun tramp-gvfs-maybe-open-connection (vec)
1557 "Maybe open a connection VEC.
1558 Does not do anything if a connection is already open, but re-opens the
1559 connection if a previous connection has died for some reason."
1560 (tramp-check-proper-method-and-host vec)
1562 ;; We set the file name, in case there are incoming D-Bus signals or
1564 (setq tramp-gvfs-dbus-event-vector vec)
1566 ;; For password handling, we need a process bound to the connection
1567 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1569 (unless (get-buffer-process (tramp-get-connection-buffer vec))
1570 (let ((p (make-network-process
1571 :name (tramp-buffer-name vec)
1572 :buffer (tramp-get-connection-buffer vec)
1573 :server t :host 'local :service t :noquery t)))
1574 (set-process-query-on-exit-flag p nil)))
1576 (unless (tramp-gvfs-connection-mounted-p vec)
1577 (let* ((method (tramp-file-name-method vec))
1578 (user (tramp-file-name-user vec))
1579 (host (tramp-file-name-host vec))
1580 (localname (tramp-file-name-localname vec))
1582 (tramp-gvfs-object-path
1583 (tramp-make-tramp-file-name method user host ""))))
1585 (when (and (string-equal method "smb")
1586 (string-equal localname "/"))
1587 (tramp-error vec 'file-error "Filename must contain a Windows share"))
1589 (when (and (string-equal method "afp")
1590 (string-equal localname "/"))
1591 (tramp-error vec 'file-error "Filename must contain an AFP volume"))
1593 (with-tramp-progress-reporter
1595 (if (zerop (length user))
1596 (format "Opening connection for %s using %s" host method)
1597 (format "Opening connection for %s@%s using %s" user host method))
1599 ;; Enable `auth-source'.
1600 (tramp-set-connection-property vec "first-password-request" t)
1602 ;; There will be a callback of "askPassword" when a password is
1604 (dbus-register-method
1605 :session dbus-service-emacs object-path
1606 tramp-gvfs-interface-mountoperation "askPassword"
1607 'tramp-gvfs-handler-askpassword)
1608 (dbus-register-method
1609 :session dbus-service-emacs object-path
1610 tramp-gvfs-interface-mountoperation "AskPassword"
1611 'tramp-gvfs-handler-askpassword)
1613 ;; There could be a callback of "askQuestion" when adding fingerprint.
1614 (dbus-register-method
1615 :session dbus-service-emacs object-path
1616 tramp-gvfs-interface-mountoperation "askQuestion"
1617 'tramp-gvfs-handler-askquestion)
1618 (dbus-register-method
1619 :session dbus-service-emacs object-path
1620 tramp-gvfs-interface-mountoperation "AskQuestion"
1621 'tramp-gvfs-handler-askquestion)
1623 ;; The call must be asynchronously, because of the "askPassword"
1624 ;; or "askQuestion"callbacks.
1625 (if (string-match "(so)$" tramp-gvfs-mountlocation-signature)
1626 (with-tramp-dbus-call-method vec nil
1627 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1628 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1629 (tramp-gvfs-mount-spec vec)
1630 `(:struct :string ,(dbus-get-unique-name :session)
1631 :object-path ,object-path))
1632 (with-tramp-dbus-call-method vec nil
1633 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1634 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1635 (tramp-gvfs-mount-spec vec)
1636 :string (dbus-get-unique-name :session) :object-path object-path))
1638 ;; We must wait, until the mount is applied. This will be
1639 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1642 ((or (tramp-get-method-parameter vec 'tramp-connection-timeout)
1643 tramp-connection-timeout)
1644 (if (zerop (length (tramp-file-name-user vec)))
1647 "Timeout reached mounting %s using %s" host method)
1650 "Timeout reached mounting %s@%s using %s" user host method)))
1651 (while (not (tramp-get-file-property vec "/" "fuse-mountpoint" nil))
1652 (read-event nil nil 0.1)))
1654 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1655 ;; is marked with the fuse-mountpoint "/". We shall react.
1657 (tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
1658 (tramp-error vec 'file-error "FUSE mount denied"))
1660 ;; Mark it as connected.
1661 (tramp-set-connection-property
1662 (tramp-get-connection-process vec) "connected" t))))
1664 ;; In `tramp-check-cached-permissions', the connection properties
1665 ;; {uig,gid}-{integer,string} are used. We set them to their local
1667 (with-tramp-connection-property
1668 vec "uid-integer" (tramp-get-local-uid 'integer))
1669 (with-tramp-connection-property
1670 vec "gid-integer" (tramp-get-local-gid 'integer))
1671 (with-tramp-connection-property
1672 vec "uid-string" (tramp-get-local-uid 'string))
1673 (with-tramp-connection-property
1674 vec "gid-string" (tramp-get-local-gid 'string)))
1676 (defun tramp-gvfs-send-command (vec command &rest args)
1677 "Send the COMMAND with its ARGS to connection VEC.
1678 COMMAND is usually a command from the gvfs-* utilities.
1679 `call-process' is applied, and it returns t if the return code is zero."
1680 (let* ((locale (tramp-get-local-locale vec))
1681 (process-environment
1683 `(,(format "LANG=%s" locale)
1684 ,(format "LANGUAGE=%s" locale)
1685 ,(format "LC_ALL=%s" locale))
1686 process-environment)))
1687 (with-current-buffer (tramp-get-connection-buffer vec)
1688 (tramp-gvfs-maybe-open-connection vec)
1690 (zerop (apply 'tramp-call-process vec command nil t nil args)))))
1693 ;; D-Bus BLUEZ functions.
1695 (defun tramp-bluez-list-devices ()
1696 "Return all discovered bluetooth devices as list.
1697 Every entry is a list (NAME ADDRESS).
1699 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1700 discovery happened more time before indicated there, a rescan will be
1701 started, which lasts some ten seconds. Otherwise, cached results will
1703 ;; Reset the scanned devices list if time has passed.
1704 (and (integerp tramp-bluez-discover-devices-timeout)
1705 (integerp tramp-bluez-discovery)
1706 (> (tramp-time-diff (current-time) tramp-bluez-discovery)
1707 tramp-bluez-discover-devices-timeout)
1708 (setq tramp-bluez-devices nil))
1710 ;; Rescan if needed.
1711 (unless tramp-bluez-devices
1713 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1714 :system tramp-bluez-service "/"
1715 tramp-bluez-interface-manager "DefaultAdapter")))
1716 (setq tramp-bluez-devices nil
1717 tramp-bluez-discovery t)
1718 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1719 :system tramp-bluez-service object-path
1720 tramp-bluez-interface-adapter "StartDiscovery")
1721 (while tramp-bluez-discovery
1722 (read-event nil nil 0.1))))
1723 (setq tramp-bluez-discovery (current-time))
1724 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-bluez-devices)
1725 tramp-bluez-devices)
1727 (defun tramp-bluez-property-changed (property value)
1728 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1729 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" property value)
1731 ((string-equal property "Discovering")
1733 ;; "Discovering" FALSE means discovery run has been completed.
1734 ;; We stop it, because we don't need another run.
1735 (setq tramp-bluez-discovery nil)
1736 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1737 :system tramp-bluez-service (dbus-event-path-name last-input-event)
1738 tramp-bluez-interface-adapter "StopDiscovery")))))
1740 (when tramp-gvfs-enabled
1741 (dbus-register-signal
1742 :system nil nil tramp-bluez-interface-adapter "PropertyChanged"
1743 'tramp-bluez-property-changed))
1745 (defun tramp-bluez-device-found (device args)
1746 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1747 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" device args)
1748 (let ((alias (car (cadr (assoc "Alias" args))))
1749 (address (car (cadr (assoc "Address" args)))))
1750 ;; Maybe we shall check the device class for being a proper
1751 ;; device, and call also SDP in order to find the obex service.
1752 (add-to-list 'tramp-bluez-devices (list alias address))))
1754 (when tramp-gvfs-enabled
1755 (dbus-register-signal
1756 :system nil nil tramp-bluez-interface-adapter "DeviceFound"
1757 'tramp-bluez-device-found))
1759 (defun tramp-bluez-parse-device-names (_ignore)
1760 "Return a list of (nil host) tuples allowed to access."
1762 (lambda (x) (list nil (car x)))
1763 (tramp-bluez-list-devices)))
1765 ;; Add completion function for OBEX method.
1766 (when (and tramp-gvfs-enabled
1767 (member tramp-bluez-service (dbus-list-known-names :system)))
1768 (tramp-set-completion-function
1769 "obex" '((tramp-bluez-parse-device-names ""))))
1772 ;; D-Bus zeroconf functions.
1774 (defun tramp-zeroconf-parse-device-names (service)
1775 "Return a list of (user host) tuples allowed to access."
1778 (let ((host (zeroconf-service-host x))
1779 (port (zeroconf-service-port x))
1780 (text (zeroconf-service-txt x))
1783 (setq host (format "%s%s%d" host tramp-prefix-port-regexp port)))
1784 ;; A user is marked in a TXT field like "u=guest".
1786 (when (string-match "u=\\(.+\\)$" (car text))
1787 (setq user (match-string 1 (car text))))
1788 (setq text (cdr text)))
1790 (zeroconf-list-services service)))
1792 ;; We use the TRIM argument of `split-string', which exist since Emacs
1793 ;; 24.4. I mask this for older Emacs versions, there is no harm.
1794 (defun tramp-gvfs-parse-device-names (service)
1795 "Return a list of (user host) tuples allowed to access.
1796 This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi."
1799 (tramp-compat-funcall
1801 (shell-command-to-string (format "avahi-browse -trkp %s" service))
1802 "[\n\r]+" 'omit "^\\+;.*$"))))
1806 (let* ((list (split-string x ";"))
1809 (text (tramp-compat-funcall
1810 'split-string (nth 9 list) "\" \"" 'omit "\""))
1812 ; (when (and port (not (string-equal port "0")))
1813 ; (setq host (format "%s%s%s" host tramp-prefix-port-regexp port)))
1814 ;; A user is marked in a TXT field like "u=guest".
1816 (when (string-match "u=\\(.+\\)$" (car text))
1817 (setq user (match-string 1 (car text))))
1818 (setq text (cdr text)))
1822 ;; Add completion functions for AFP, DAV, DAVS, SFTP and SMB methods.
1823 (when tramp-gvfs-enabled
1824 ;; Suppress D-Bus error messages.
1825 (let (tramp-gvfs-dbus-event-vector)
1826 (zeroconf-init tramp-gvfs-zeroconf-domain)
1827 (if (zeroconf-list-service-types)
1829 (tramp-set-completion-function
1830 "afp" '((tramp-zeroconf-parse-device-names "_afpovertcp._tcp")))
1831 (tramp-set-completion-function
1832 "dav" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
1833 (tramp-set-completion-function
1834 "davs" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
1835 (tramp-set-completion-function
1836 "sftp" '((tramp-zeroconf-parse-device-names "_ssh._tcp")
1837 (tramp-zeroconf-parse-device-names "_workstation._tcp")))
1838 (when (member "smb" tramp-gvfs-methods)
1839 (tramp-set-completion-function
1840 "smb" '((tramp-zeroconf-parse-device-names "_smb._tcp")))))
1842 (when (executable-find "avahi-browse")
1843 (tramp-set-completion-function
1844 "afp" '((tramp-gvfs-parse-device-names "_afpovertcp._tcp")))
1845 (tramp-set-completion-function
1846 "dav" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
1847 (tramp-set-completion-function
1848 "davs" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
1849 (tramp-set-completion-function
1850 "sftp" '((tramp-gvfs-parse-device-names "_ssh._tcp")
1851 (tramp-gvfs-parse-device-names "_workstation._tcp")))
1852 (when (member "smb" tramp-gvfs-methods)
1853 (tramp-set-completion-function
1854 "smb" '((tramp-gvfs-parse-device-names "_smb._tcp"))))))))
1857 ;; D-Bus SYNCE functions.
1859 (defun tramp-synce-list-devices ()
1860 "Return all discovered synce devices as list.
1861 They are retrieved from the hal daemon."
1862 (let (tramp-synce-devices)
1864 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1865 :system tramp-hal-service tramp-hal-path-manager
1866 tramp-hal-interface-manager "GetAllDevices"))
1867 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1868 :system tramp-hal-service device tramp-hal-interface-device
1869 "PropertyExists" "sync.plugin")
1871 (with-tramp-dbus-call-method
1872 tramp-gvfs-dbus-event-vector t
1873 :system tramp-hal-service device tramp-hal-interface-device
1874 "GetPropertyString" "pda.pocketpc.name")))
1875 (unless (member prop tramp-synce-devices)
1876 (push prop tramp-synce-devices)))))
1877 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-synce-devices)
1878 tramp-synce-devices))
1880 (defun tramp-synce-parse-device-names (_ignore)
1881 "Return a list of (nil host) tuples allowed to access."
1883 (lambda (x) (list nil x))
1884 (tramp-synce-list-devices)))
1886 ;; Add completion function for SYNCE method.
1887 (when tramp-gvfs-enabled
1888 (tramp-set-completion-function
1889 "synce" '((tramp-synce-parse-device-names ""))))
1891 (add-hook 'tramp-unload-hook
1893 (unload-feature 'tramp-gvfs 'force)))
1895 (provide 'tramp-gvfs)
1899 ;; * Host name completion via afp-server, smb-server or smb-network.
1900 ;; * Check how two shares of the same SMB server can be mounted in
1902 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1904 ;; * Implement obex for other serial communication but bluetooth.
1906 ;;; tramp-gvfs.el ends here