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.")
411 ;; New handlers should be added here.
412 (defconst tramp-gvfs-file-name-handler-alist
413 '((access-file . ignore)
414 (add-name-to-file . tramp-gvfs-handle-copy-file)
415 ;; `byte-compiler-base-file-name' performed by default handler.
416 ;; `copy-directory' performed by default handler.
417 (copy-file . tramp-gvfs-handle-copy-file)
418 (delete-directory . tramp-gvfs-handle-delete-directory)
419 (delete-file . tramp-gvfs-handle-delete-file)
420 ;; `diff-latest-backup-file' performed by default handler.
421 (directory-file-name . tramp-handle-directory-file-name)
422 (directory-files . tramp-handle-directory-files)
423 (directory-files-and-attributes
424 . tramp-handle-directory-files-and-attributes)
425 (dired-compress-file . ignore)
426 (dired-uncache . tramp-handle-dired-uncache)
427 (expand-file-name . tramp-gvfs-handle-expand-file-name)
428 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
430 (file-attributes . tramp-gvfs-handle-file-attributes)
431 (file-directory-p . tramp-gvfs-handle-file-directory-p)
432 (file-equal-p . tramp-handle-file-equal-p)
433 (file-executable-p . tramp-gvfs-handle-file-executable-p)
434 (file-exists-p . tramp-handle-file-exists-p)
435 (file-in-directory-p . tramp-handle-file-in-directory-p)
436 (file-local-copy . tramp-gvfs-handle-file-local-copy)
437 (file-modes . tramp-handle-file-modes)
438 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
439 (file-name-as-directory . tramp-handle-file-name-as-directory)
440 (file-name-completion . tramp-handle-file-name-completion)
441 (file-name-directory . tramp-handle-file-name-directory)
442 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
443 ;; `file-name-sans-versions' performed by default handler.
444 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
445 (file-notify-add-watch . tramp-gvfs-handle-file-notify-add-watch)
446 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
447 (file-notify-valid-p . tramp-handle-file-notify-valid-p)
448 (file-ownership-preserved-p . ignore)
449 (file-readable-p . tramp-gvfs-handle-file-readable-p)
450 (file-regular-p . tramp-handle-file-regular-p)
451 (file-remote-p . tramp-handle-file-remote-p)
452 (file-selinux-context . ignore)
453 (file-symlink-p . tramp-handle-file-symlink-p)
454 ;; `file-truename' performed by default handler.
455 (file-writable-p . tramp-gvfs-handle-file-writable-p)
456 (find-backup-file-name . tramp-handle-find-backup-file-name)
457 ;; `find-file-noselect' performed by default handler.
458 ;; `get-file-buffer' performed by default handler.
459 (insert-directory . tramp-handle-insert-directory)
460 (insert-file-contents . tramp-handle-insert-file-contents)
461 (load . tramp-handle-load)
462 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
463 (make-directory . tramp-gvfs-handle-make-directory)
464 (make-directory-internal . ignore)
465 (make-symbolic-link . tramp-handle-make-symbolic-link)
466 (process-file . ignore)
467 (rename-file . tramp-gvfs-handle-rename-file)
468 (set-file-acl . ignore)
469 (set-file-modes . ignore)
470 (set-file-selinux-context . ignore)
471 (set-file-times . ignore)
472 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
473 (shell-command . ignore)
474 (start-file-process . ignore)
475 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
476 (unhandled-file-name-directory . ignore)
477 (vc-registered . ignore)
478 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
479 (write-region . tramp-gvfs-handle-write-region))
480 "Alist of handler functions for Tramp GVFS method.
481 Operations not mentioned here will be handled by the default Emacs primitives.")
483 ;; It must be a `defsubst' in order to push the whole code into
484 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
486 (defsubst tramp-gvfs-file-name-p (filename)
487 "Check if it's a filename handled by the GVFS daemon."
488 (and (tramp-tramp-file-p filename)
490 (tramp-file-name-method (tramp-dissect-file-name filename))))
491 (and (stringp method) (member method tramp-gvfs-methods)))))
494 (defun tramp-gvfs-file-name-handler (operation &rest args)
495 "Invoke the GVFS related OPERATION.
496 First arg specifies the OPERATION, second arg is a list of arguments to
497 pass to the OPERATION."
498 (unless tramp-gvfs-enabled
499 (tramp-user-error nil "Package `tramp-gvfs' not supported"))
500 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
502 (save-match-data (apply (cdr fn) args))
503 (tramp-run-real-handler operation args))))
505 ;; This might be moved to tramp.el. It shall be the first file name
508 (when (featurep 'dbusbind)
509 (add-to-list 'tramp-foreign-file-name-handler-alist
510 (cons 'tramp-gvfs-file-name-p 'tramp-gvfs-file-name-handler)))
513 ;; D-Bus helper function.
515 (defun tramp-gvfs-dbus-string-to-byte-array (string)
516 "Like `dbus-string-to-byte-array' but add trailing \\0 if needed."
517 (dbus-string-to-byte-array
518 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
519 (concat string (string 0)) string)))
521 (defun tramp-gvfs-dbus-byte-array-to-string (byte-array)
522 "Like `dbus-byte-array-to-string' but remove trailing \\0 if exists."
523 ;; The byte array could be a variant. Take care.
525 (if (and (consp byte-array) (atom (car byte-array)))
526 byte-array (car byte-array))))
527 (dbus-byte-array-to-string
528 (if (and (consp byte-array) (zerop (car (last byte-array))))
529 (butlast byte-array) byte-array))))
531 (defun tramp-gvfs-stringify-dbus-message (message)
532 "Convert a D-Bus message into readable UTF8 strings, used for traces."
534 ((and (consp message) (characterp (car message)))
535 (format "%S" (tramp-gvfs-dbus-byte-array-to-string message)))
537 (mapcar 'tramp-gvfs-stringify-dbus-message message))
539 (format "%S" message))
542 (defmacro with-tramp-dbus-call-method
543 (vec synchronous bus service path interface method &rest args)
544 "Apply a D-Bus call on bus BUS.
546 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
547 it is an asynchronous call, with `ignore' as callback function.
549 The other arguments have the same meaning as with `dbus-call-method'
550 or `dbus-call-method-asynchronously'. Additionally, the call
551 will be traced by Tramp with trace level 6."
552 `(let ((func (if ,synchronous
553 'dbus-call-method 'dbus-call-method-asynchronously))
554 (args (append (list ,bus ,service ,path ,interface ,method)
555 (if ,synchronous (list ,@args) (list 'ignore ,@args))))
557 (tramp-message ,vec 6 "%s %s" func args)
558 (setq result (apply func args))
559 (tramp-message ,vec 6 "%s" (tramp-gvfs-stringify-dbus-message result))
562 (put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
563 (put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
564 (font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
566 (defvar tramp-gvfs-dbus-event-vector nil
567 "Current Tramp file name to be used, as vector.
568 It is needed when D-Bus signals or errors arrive, because there
569 is no information where to trace the message.")
571 (defun tramp-gvfs-dbus-event-error (event err)
572 "Called when a D-Bus error message arrives, see `dbus-event-error-functions'."
573 (when tramp-gvfs-dbus-event-vector
574 (tramp-message tramp-gvfs-dbus-event-vector 10 "%S" event)
575 (tramp-error tramp-gvfs-dbus-event-vector 'file-error "%s" (cadr err))))
577 ;; `dbus-event-error-hooks' has been renamed to `dbus-event-error-functions'.
579 (if (boundp 'dbus-event-error-functions)
580 'dbus-event-error-functions 'dbus-event-error-hooks)
581 'tramp-gvfs-dbus-event-error)
584 ;; File name primitives.
586 (defun tramp-gvfs-do-copy-or-rename-file
587 (op filename newname &optional ok-if-already-exists keep-date
588 preserve-uid-gid preserve-extended-attributes)
589 "Copy or rename a remote file.
590 OP must be `copy' or `rename' and indicates the operation to perform.
591 FILENAME specifies the file to copy or rename, NEWNAME is the name of
592 the new file (for copy) or the new name of the file (for rename).
593 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
594 KEEP-DATE means to make sure that NEWNAME has the same timestamp
595 as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
596 the uid and gid if both files are on the same host.
597 PRESERVE-EXTENDED-ATTRIBUTES is ignored.
599 This function is invoked by `tramp-gvfs-handle-copy-file' and
600 `tramp-gvfs-handle-rename-file'. It is an error if OP is neither
601 of `copy' and `rename'. FILENAME and NEWNAME must be absolute
603 (unless (memq op '(copy rename))
604 (error "Unknown operation `%s', must be `copy' or `rename'" op))
606 (let ((t1 (tramp-tramp-file-p filename))
607 (t2 (tramp-tramp-file-p newname))
608 (equal-remote (tramp-equal-remote filename newname))
609 (file-operation (intern (format "%s-file" op)))
610 (gvfs-operation (if (eq op 'copy) "gvfs-copy" "gvfs-move"))
611 (msg-operation (if (eq op 'copy) "Copying" "Renaming")))
613 (with-parsed-tramp-file-name (if t1 filename newname) nil
614 (when (and (not ok-if-already-exists) (file-exists-p newname))
616 v 'file-already-exists "File %s already exists" newname))
618 (if (or (and equal-remote
619 (tramp-get-connection-property v "direct-copy-failed" nil))
620 (and t1 (not (tramp-gvfs-file-name-p filename)))
621 (and t2 (not (tramp-gvfs-file-name-p newname))))
623 ;; We cannot copy or rename directly.
624 ;; PRESERVE-EXTENDED-ATTRIBUTES has been introduced with
625 ;; Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and renamed
627 (let ((tmpfile (tramp-compat-make-temp-file filename)))
629 (preserve-extended-attributes
632 filename tmpfile t keep-date preserve-uid-gid
633 preserve-extended-attributes))
636 file-operation filename tmpfile t keep-date preserve-uid-gid)))
637 (rename-file tmpfile newname ok-if-already-exists))
640 (with-tramp-progress-reporter
641 v 0 (format "%s %s to %s" msg-operation filename newname)
644 'tramp-gvfs-send-command v gvfs-operation
646 (and (eq op 'copy) (or keep-date preserve-uid-gid)
649 (tramp-gvfs-url-file-name filename)
650 (tramp-gvfs-url-file-name newname))))
652 (if (or (not equal-remote)
654 (tramp-get-connection-property
655 v "direct-copy-failed" nil)))
656 ;; Propagate the error.
657 (with-current-buffer (tramp-get-connection-buffer v)
658 (goto-char (point-min))
659 (tramp-error-with-buffer
661 "%s failed, see buffer `%s' for details."
662 msg-operation (buffer-name)))
664 ;; Some WebDAV server, like the one from QNAP, do not
665 ;; support direct copy/move. Try a fallback.
666 (tramp-set-connection-property v "direct-copy-failed" t)
667 (tramp-gvfs-do-copy-or-rename-file
668 op filename newname ok-if-already-exists keep-date
669 preserve-uid-gid preserve-extended-attributes))))
671 (when (and t1 (eq op 'rename))
672 (with-parsed-tramp-file-name filename nil
673 (tramp-flush-file-property v (file-name-directory localname))
674 (tramp-flush-file-property v localname)))
677 (with-parsed-tramp-file-name newname nil
678 (tramp-flush-file-property v (file-name-directory localname))
679 (tramp-flush-file-property v localname)))))))
681 (defun tramp-gvfs-handle-copy-file
682 (filename newname &optional ok-if-already-exists keep-date
683 preserve-uid-gid preserve-extended-attributes)
684 "Like `copy-file' for Tramp files."
685 (setq filename (expand-file-name filename))
686 (setq newname (expand-file-name newname))
688 ;; At least one file a Tramp file?
689 ((or (tramp-tramp-file-p filename)
690 (tramp-tramp-file-p newname))
691 (tramp-gvfs-do-copy-or-rename-file
692 'copy filename newname ok-if-already-exists keep-date
693 preserve-uid-gid preserve-extended-attributes))
694 ;; Compat section. PRESERVE-EXTENDED-ATTRIBUTES has been
695 ;; introduced with Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and
696 ;; renamed in Emacs 24.3.
697 (preserve-extended-attributes
698 (tramp-run-real-handler
700 (list filename newname ok-if-already-exists keep-date
701 preserve-uid-gid preserve-extended-attributes)))
703 (tramp-run-real-handler
705 (list filename newname ok-if-already-exists keep-date preserve-uid-gid)))))
707 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash)
708 "Like `delete-directory' for Tramp files."
709 (when (and recursive (not (file-symlink-p directory)))
711 (if (eq t (car (file-attributes file)))
712 (tramp-compat-delete-directory file recursive trash)
713 (tramp-compat-delete-file file trash)))
715 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
716 (with-parsed-tramp-file-name directory nil
717 (tramp-flush-file-property v (file-name-directory localname))
718 (tramp-flush-directory-property v localname)
720 (tramp-gvfs-send-command
721 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
722 (tramp-gvfs-url-file-name directory))
723 ;; Propagate the error.
724 (with-current-buffer (tramp-get-connection-buffer v)
725 (goto-char (point-min))
726 (tramp-error-with-buffer
727 nil v 'file-error "Couldn't delete %s" directory)))))
729 (defun tramp-gvfs-handle-delete-file (filename &optional trash)
730 "Like `delete-file' for Tramp files."
731 (with-parsed-tramp-file-name filename nil
732 (tramp-flush-file-property v (file-name-directory localname))
733 (tramp-flush-file-property v localname)
735 (tramp-gvfs-send-command
736 v (if (and trash delete-by-moving-to-trash) "gvfs-trash" "gvfs-rm")
737 (tramp-gvfs-url-file-name filename))
738 ;; Propagate the error.
739 (with-current-buffer (tramp-get-connection-buffer v)
740 (goto-char (point-min))
741 (tramp-error-with-buffer
742 nil v 'file-error "Couldn't delete %s" filename)))))
744 (defun tramp-gvfs-handle-expand-file-name (name &optional dir)
745 "Like `expand-file-name' for Tramp files."
746 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
747 (setq dir (or dir default-directory "/"))
748 ;; Unless NAME is absolute, concat DIR and NAME.
749 (unless (file-name-absolute-p name)
750 (setq name (concat (file-name-as-directory dir) name)))
751 ;; If NAME is not a Tramp file, run the real handler.
752 (if (not (tramp-tramp-file-p name))
753 (tramp-run-real-handler 'expand-file-name (list name nil))
755 (with-parsed-tramp-file-name name nil
756 ;; If there is a default location, expand tilde.
757 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname)
759 (tramp-gvfs-maybe-open-connection (vector method user host "/" hop)))
762 (tramp-get-file-property v "/" "default-location" "~")
764 ;; Tilde expansion is not possible.
765 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
768 "Cannot expand tilde in file `%s'" name))
769 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
770 (setq localname (concat "/" localname)))
771 ;; We do not pass "/..".
772 (if (string-match "^\\(afp\\|smb\\)$" method)
773 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname)
774 (setq localname (replace-match "/" t t localname 1)))
775 (when (string-match "^/\\.\\./?" localname)
776 (setq localname (replace-match "/" t t localname))))
777 ;; There might be a double slash. Remove this.
778 (while (string-match "//" localname)
779 (setq localname (replace-match "/" t t localname)))
780 ;; No tilde characters in file name, do normal
781 ;; `expand-file-name' (this does "/./" and "/../").
782 (tramp-make-tramp-file-name
784 (tramp-run-real-handler
785 'expand-file-name (list localname))))))
787 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
788 "Like `file-attributes' for Tramp files."
789 (unless id-format (setq id-format 'integer))
791 ;; Don't modify `last-coding-system-used' by accident.
792 (let ((last-coding-system-used last-coding-system-used)
793 (process-environment (cons "LC_MESSAGES=C" process-environment))
794 dirp res-symlink-target res-numlinks res-uid res-gid res-access
795 res-mod res-change res-size res-filemodes res-inode res-device)
796 (with-parsed-tramp-file-name filename nil
797 (with-tramp-file-property
798 v localname (format "file-attributes-%s" id-format)
799 (tramp-message v 5 "file attributes: %s" localname)
800 (tramp-gvfs-send-command
801 v "gvfs-info" (tramp-gvfs-url-file-name filename))
803 (with-current-buffer (tramp-get-connection-buffer v)
804 (goto-char (point-min))
805 (when (re-search-forward "attributes:" nil t)
806 ;; ... directory or symlink
807 (goto-char (point-min))
808 (setq dirp (if (re-search-forward "type: directory" nil t) t))
809 (goto-char (point-min))
810 (setq res-symlink-target
811 (if (re-search-forward
812 "standard::symlink-target: \\(.+\\)$" nil t)
815 (goto-char (point-min))
817 (if (re-search-forward "unix::nlink: \\([0-9]+\\)" nil t)
818 (string-to-number (match-string 1)) 0))
820 (goto-char (point-min))
822 (if (eq id-format 'integer)
823 (if (re-search-forward "unix::uid: \\([0-9]+\\)" nil t)
824 (string-to-number (match-string 1))
826 (if (re-search-forward "owner::user: \\(.+\\)$" nil t)
830 (if (eq id-format 'integer)
831 (if (re-search-forward "unix::gid: \\([0-9]+\\)" nil t)
832 (string-to-number (match-string 1))
834 (if (re-search-forward "owner::group: \\(.+\\)$" nil t)
837 ;; ... last access, modification and change time
838 (goto-char (point-min))
840 (if (re-search-forward "time::access: \\([0-9]+\\)" nil t)
841 (seconds-to-time (string-to-number (match-string 1)))
843 (goto-char (point-min))
845 (if (re-search-forward "time::modified: \\([0-9]+\\)" nil t)
846 (seconds-to-time (string-to-number (match-string 1)))
848 (goto-char (point-min))
850 (if (re-search-forward "time::changed: \\([0-9]+\\)" nil t)
851 (seconds-to-time (string-to-number (match-string 1)))
854 (goto-char (point-min))
856 (if (re-search-forward "standard::size: \\([0-9]+\\)" nil t)
857 (string-to-number (match-string 1)) 0))
858 ;; ... file mode flags
859 (goto-char (point-min))
861 (if (re-search-forward "unix::mode: \\([0-9]+\\)" nil t)
862 (tramp-file-mode-from-int
863 (string-to-number (match-string 1)))
864 (if dirp "drwx------" "-rwx------")))
865 ;; ... inode and device
866 (goto-char (point-min))
868 (if (re-search-forward "unix::inode: \\([0-9]+\\)" nil t)
869 (string-to-number (match-string 1))
870 (tramp-get-inode v)))
871 (goto-char (point-min))
873 (if (re-search-forward "unix::device: \\([0-9]+\\)" nil t)
874 (string-to-number (match-string 1))
875 (tramp-get-device v)))
877 ;; Return data gathered.
879 ;; 0. t for directory, string (name linked to) for
880 ;; symbolic link, or nil.
881 (or dirp res-symlink-target)
882 ;; 1. Number of links to file.
888 ;; 4. Last access time, as a list of integers.
889 ;; 5. Last modification time, likewise.
890 ;; 6. Last status change time, likewise.
891 res-access res-mod res-change
892 ;; 7. Size in bytes (-1, if number is out of range).
896 ;; 9. t if file's gid would change if file were deleted
901 ;; 11. Device number.
905 (defun tramp-gvfs-handle-file-directory-p (filename)
906 "Like `file-directory-p' for Tramp files."
907 (eq t (car (file-attributes filename))))
909 (defun tramp-gvfs-handle-file-executable-p (filename)
910 "Like `file-executable-p' for Tramp files."
911 (with-parsed-tramp-file-name filename nil
912 (with-tramp-file-property v localname "file-executable-p"
913 (tramp-check-cached-permissions v ?x))))
915 (defun tramp-gvfs-handle-file-local-copy (filename)
916 "Like `file-local-copy' for Tramp files."
917 (with-parsed-tramp-file-name filename nil
918 (let ((tmpfile (tramp-compat-make-temp-file filename)))
919 (unless (file-exists-p filename)
922 "Cannot make local copy of non-existing file `%s'" filename))
923 (copy-file filename tmpfile 'ok-if-already-exists 'keep-time)
926 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
927 "Like `file-name-all-completions' for Tramp files."
928 (unless (save-match-data (string-match "/" filename))
929 (with-parsed-tramp-file-name (expand-file-name directory) nil
936 ;; Try cache entries for filename, filename with last
937 ;; character removed, filename with last two characters
938 ;; removed, ..., and finally the empty string - all
939 ;; concatenated to the local directory name.
940 (let ((remote-file-name-inhibit-cache
941 (or remote-file-name-inhibit-cache
942 tramp-completion-reread-directory-timeout)))
944 ;; This is inefficient for very long filenames, pity
945 ;; `reduce' is not available...
952 (tramp-get-file-property
954 (concat localname (substring filename 0 x))
955 "file-name-all-completions"
957 (when cache-hit (list cache-hit))))
958 ;; We cannot use a length of 0, because file properties
959 ;; for "foo" and "foo/" are identical.
960 (number-sequence (length filename) 1 -1)))))
962 ;; Cache expired or no matching cache entry found so we need
963 ;; to perform a remote operation.
964 (let ((result '("." ".."))
966 ;; Get a list of directories and files.
967 (tramp-gvfs-send-command
968 v "gvfs-ls" "-h" (tramp-gvfs-url-file-name directory))
970 ;; Now grab the output.
972 (insert-buffer-substring (tramp-get-connection-buffer v))
973 (goto-char (point-max))
974 (while (zerop (forward-line -1))
975 (setq entry (buffer-substring (point) (point-at-eol)))
976 (when (string-match filename entry)
977 (if (file-directory-p (expand-file-name entry directory))
978 (push (concat entry "/") result)
979 (push entry result)))))
981 ;; Because the remote op went through OK we know the
982 ;; directory we `cd'-ed to exists.
983 (tramp-set-file-property v localname "file-exists-p" t)
985 ;; Because the remote op went through OK we know every
986 ;; file listed by `ls' exists.
987 (mapc (lambda (entry)
988 (tramp-set-file-property
989 v (concat localname entry) "file-exists-p" t))
992 ;; Store result in the cache.
993 (tramp-set-file-property
994 v (concat localname filename)
995 "file-name-all-completions" result))))))))
997 (defun tramp-gvfs-handle-file-notify-add-watch (file-name flags _callback)
998 "Like `file-notify-add-watch' for Tramp files."
999 (setq file-name (expand-file-name file-name))
1000 (with-parsed-tramp-file-name file-name nil
1001 ;; We cannot watch directories, because `gvfs-monitor-dir' is not
1002 ;; supported for gvfs-mounted directories.
1003 (when (file-directory-p file-name)
1005 v 'file-notify-error "Monitoring not supported for `%s'" file-name))
1006 (let* ((default-directory (file-name-directory file-name))
1009 ((and (memq 'change flags) (memq 'attribute-change flags))
1010 '(created changed changes-done-hint moved deleted
1012 ((memq 'change flags)
1013 '(created changed changes-done-hint moved deleted))
1014 ((memq 'attribute-change flags) '(attribute-changed))))
1016 "gvfs-monitor-file" (generate-new-buffer " *gvfs-monitor-file*")
1017 "gvfs-monitor-file" (tramp-gvfs-url-file-name file-name))))
1018 (if (not (processp p))
1020 v 'file-notify-error "Monitoring not supported for `%s'" file-name)
1022 v 6 "Run `%s', %S" (mapconcat 'identity (process-command p) " ") p)
1023 (tramp-set-connection-property p "vector" v)
1024 (process-put p 'events events)
1025 (process-put p 'watch-name localname)
1026 (set-process-query-on-exit-flag p nil)
1027 (set-process-filter p 'tramp-gvfs-monitor-file-process-filter)
1028 ;; There might be an error if the monitor is not supported.
1029 ;; Give the filter a chance to read the output.
1030 (tramp-accept-process-output p 1)
1031 (unless (memq (process-status p) '(run open))
1033 v 'file-notify-error "Monitoring not supported for `%s'" file-name))
1036 (defun tramp-gvfs-monitor-file-process-filter (proc string)
1037 "Read output from \"gvfs-monitor-file\" and add corresponding \
1038 file-notify events."
1039 (let* ((rest-string (process-get proc 'rest-string))
1040 (dd (with-current-buffer (process-buffer proc) default-directory))
1041 (ddu (regexp-quote (tramp-gvfs-url-file-name dd))))
1043 (tramp-message proc 10 "Previous string:\n%s" rest-string))
1044 (tramp-message proc 6 "%S\n%s" proc string)
1045 (setq string (concat rest-string string)
1046 ;; Attribute change is returned in unused wording.
1047 string (replace-regexp-in-string
1048 "ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string))
1049 (when (string-match "Monitoring not supported" string)
1050 (delete-process proc))
1052 (while (string-match
1054 "File Monitor Event:[\n\r]+"
1055 "File = \\([^\n\r]+\\)[\n\r]+"
1056 "Event = \\([^[:blank:]]+\\)[\n\r]+")
1058 (let ((file (match-string 1 string))
1059 (action (intern-soft
1060 (replace-regexp-in-string
1061 "_" "-" (downcase (match-string 2 string))))))
1062 (setq string (replace-match "" nil nil string))
1063 ;; File names are returned as URL paths. We must convert them.
1064 (when (string-match ddu file)
1065 (setq file (replace-match dd nil nil file)))
1066 (while (string-match "%\\([0-9A-F]\\{2\\}\\)" file)
1069 (char-to-string (string-to-number (match-string 1 file) 16))
1071 ;; Usually, we would add an Emacs event now. Unfortunately,
1072 ;; `unread-command-events' does not accept several events at
1073 ;; once. Therefore, we apply the callback directly.
1074 (tramp-compat-funcall 'file-notify-callback (list proc action file))))
1076 ;; Save rest of the string.
1077 (when (zerop (length string)) (setq string nil))
1078 (when string (tramp-message proc 10 "Rest string:\n%s" string))
1079 (process-put proc 'rest-string string)))
1081 (defun tramp-gvfs-handle-file-readable-p (filename)
1082 "Like `file-readable-p' for Tramp files."
1083 (with-parsed-tramp-file-name filename nil
1084 (with-tramp-file-property v localname "file-readable-p"
1085 (tramp-check-cached-permissions v ?r))))
1087 (defun tramp-gvfs-handle-file-writable-p (filename)
1088 "Like `file-writable-p' for Tramp files."
1089 (with-parsed-tramp-file-name filename nil
1090 (with-tramp-file-property v localname "file-writable-p"
1091 (if (file-exists-p filename)
1092 (tramp-check-cached-permissions v ?w)
1093 ;; If file doesn't exist, check if directory is writable.
1094 (and (file-directory-p (file-name-directory filename))
1095 (file-writable-p (file-name-directory filename)))))))
1097 (defun tramp-gvfs-handle-make-directory (dir &optional parents)
1098 "Like `make-directory' for Tramp files."
1099 (setq dir (directory-file-name (expand-file-name dir)))
1100 (with-parsed-tramp-file-name dir nil
1101 (tramp-flush-file-property v (file-name-directory localname))
1102 (tramp-flush-directory-property v localname)
1104 (let ((ldir (file-name-directory dir)))
1105 ;; Make missing directory parts. "gvfs-mkdir -p ..." does not
1107 (when (and parents (not (file-directory-p ldir)))
1108 (make-directory ldir parents))
1110 (unless (tramp-gvfs-send-command
1111 v "gvfs-mkdir" (tramp-gvfs-url-file-name dir))
1112 (tramp-error v 'file-error "Couldn't make directory %s" dir))))))
1114 (defun tramp-gvfs-handle-rename-file
1115 (filename newname &optional ok-if-already-exists)
1116 "Like `rename-file' for Tramp files."
1117 ;; Check if both files are local -- invoke normal rename-file.
1118 ;; Otherwise, use Tramp from local system.
1119 (setq filename (expand-file-name filename))
1120 (setq newname (expand-file-name newname))
1121 ;; At least one file a Tramp file?
1122 (if (or (tramp-tramp-file-p filename)
1123 (tramp-tramp-file-p newname))
1124 (tramp-gvfs-do-copy-or-rename-file
1125 'rename filename newname ok-if-already-exists
1126 'keep-date 'preserve-uid-gid)
1127 (tramp-run-real-handler
1128 'rename-file (list filename newname ok-if-already-exists))))
1130 (defun tramp-gvfs-handle-write-region
1131 (start end filename &optional append visit lockname confirm)
1132 "Like `write-region' for Tramp files."
1133 (with-parsed-tramp-file-name filename nil
1134 (when (and confirm (file-exists-p filename))
1135 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
1136 (tramp-error v 'file-error "File not overwritten")))
1138 (let ((tmpfile (tramp-compat-make-temp-file filename)))
1139 (when (and append (file-exists-p filename))
1140 (copy-file filename tmpfile 'ok))
1141 ;; We say `no-message' here because we don't want the visited file
1142 ;; modtime data to be clobbered from the temp file. We call
1143 ;; `set-visited-file-modtime' ourselves later on.
1144 (tramp-run-real-handler
1146 (if confirm ; don't pass this arg unless defined for backward compat.
1147 (list start end tmpfile append 'no-message lockname confirm)
1148 (list start end tmpfile append 'no-message lockname)))
1150 (rename-file tmpfile filename 'ok-if-already-exists)
1152 (delete-file tmpfile)
1154 v 'file-error "Couldn't write region to `%s'" filename))))
1156 (tramp-flush-file-property v (file-name-directory localname))
1157 (tramp-flush-file-property v localname)
1159 ;; Set file modification time.
1160 (when (or (eq visit t) (stringp visit))
1161 (set-visited-file-modtime (nth 5 (file-attributes filename))))
1164 (when (or (eq visit t) (null visit) (stringp visit))
1165 (tramp-message v 0 "Wrote %s" filename))
1166 (run-hooks 'tramp-handle-write-region-hook)))
1169 ;; File name conversions.
1171 (defun tramp-gvfs-url-file-name (filename)
1172 "Return FILENAME in URL syntax."
1173 ;; "/" must NOT be hexlified.
1174 (let ((url-unreserved-chars (cons ?/ url-unreserved-chars))
1179 (if (tramp-tramp-file-p filename)
1180 (with-parsed-tramp-file-name filename nil
1181 (when (and user (string-match tramp-user-with-domain-regexp user))
1183 (concat (match-string 2 user) ";" (match-string 1 user))))
1184 (url-parse-make-urlobj
1185 method (and user (url-hexify-string user)) nil
1186 (tramp-file-name-real-host v) (tramp-file-name-port v)
1187 (and localname (url-hexify-string localname)) nil nil t))
1188 (url-parse-make-urlobj
1189 "file" nil nil nil nil
1190 (url-hexify-string (file-truename filename)) nil nil t))))
1191 (when (tramp-tramp-file-p filename)
1192 (with-parsed-tramp-file-name filename nil
1193 (tramp-message v 10 "remote file `%s' is URL `%s'" filename result)))
1196 (defun tramp-gvfs-object-path (filename)
1197 "Create a D-Bus object path from FILENAME."
1198 (expand-file-name (dbus-escape-as-identifier filename) tramp-gvfs-path-tramp))
1200 (defun tramp-gvfs-file-name (object-path)
1201 "Retrieve file name from D-Bus OBJECT-PATH."
1202 (dbus-unescape-from-identifier
1203 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
1205 (defun tramp-bluez-address (device)
1206 "Return bluetooth device address from a given bluetooth DEVICE name."
1207 (when (stringp device)
1208 (if (string-match tramp-ipv6-regexp device)
1209 (match-string 0 device)
1210 (cadr (assoc device (tramp-bluez-list-devices))))))
1212 (defun tramp-bluez-device (address)
1213 "Return bluetooth device name from a given bluetooth device ADDRESS.
1214 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
1215 (when (stringp address)
1216 (while (string-match "[][]" address)
1217 (setq address (replace-match "" t t address)))
1219 (dolist (item (tramp-bluez-list-devices) result)
1220 (when (string-match address (cadr item))
1221 (setq result (car item)))))))
1224 ;; D-Bus GVFS functions.
1226 (defun tramp-gvfs-handler-askpassword (message user domain flags)
1227 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
1229 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)))
1233 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message)
1234 (capitalize (match-string 1 message))
1240 (with-parsed-tramp-file-name filename l
1241 (when (and (zerop (length user))
1243 (zerop (logand flags tramp-gvfs-password-need-username))))
1244 (setq user (read-string "User name: ")))
1245 (when (and (zerop (length domain))
1247 (zerop (logand flags tramp-gvfs-password-need-domain))))
1248 (setq domain (read-string "Domain name: ")))
1250 (tramp-message l 6 "%S %S %S %d" message user domain flags)
1251 (unless (tramp-get-connection-property l "first-password-request" nil)
1252 (tramp-clear-passwd l))
1254 (setq tramp-current-method l-method
1255 tramp-current-user user
1256 tramp-current-host l-host
1257 password (tramp-read-passwd
1258 (tramp-get-connection-process l) pw-prompt))
1261 (if (stringp password)
1263 t ;; password handled.
1264 nil ;; no abort of D-Bus.
1266 (tramp-file-name-real-user l)
1268 nil ;; not anonymous.
1269 0) ;; no password save.
1270 ;; No password provided.
1271 (list nil t "" (tramp-file-name-real-user l) domain nil 0)))
1273 ;; When QUIT is raised, we shall return this information to D-Bus.
1274 (quit (list nil t "" "" "" nil 0)))))
1276 (defun tramp-gvfs-handler-askquestion (message choices)
1277 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
1278 (save-window-excursion
1279 (let ((enable-recursive-minibuffers t)
1283 (with-parsed-tramp-file-name
1284 (tramp-gvfs-file-name (dbus-event-path-name last-input-event)) nil
1285 (tramp-message v 6 "%S %S" message choices)
1287 ;; In theory, there can be several choices. Until now,
1288 ;; there is only the question whether to accept an unknown
1291 ;; Preserve message for `progress-reporter'.
1292 (with-temp-message ""
1294 (pop-to-buffer (current-buffer))
1295 (setq choice (if (yes-or-no-p (concat (car choices) " ")) 0 1))
1296 (tramp-message v 6 "%d" choice)))
1298 ;; When the choice is "no", we set a dummy fuse-mountpoint
1299 ;; in order to leave the timeout.
1300 (unless (zerop choice)
1301 (tramp-set-file-property v "/" "fuse-mountpoint" "/"))
1305 nil ;; no abort of D-Bus.
1308 ;; When QUIT is raised, we shall return this information to D-Bus.
1309 (quit (list nil t 0))))))
1311 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
1312 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
1313 \"org.gtk.vfs.MountTracker.unmounted\" signals."
1315 (let ((signal-name (dbus-event-member-name last-input-event))
1317 ;; Jump over the first elements of the mount info. Since there
1318 ;; were changes in the entries, we cannot access dedicated
1320 (while (stringp (car elt)) (setq elt (cdr elt)))
1321 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string (cadr elt)))
1322 (mount-spec (caddr elt))
1323 (default-location (tramp-gvfs-dbus-byte-array-to-string
1325 (method (tramp-gvfs-dbus-byte-array-to-string
1326 (cadr (assoc "type" (cadr mount-spec)))))
1327 (user (tramp-gvfs-dbus-byte-array-to-string
1328 (cadr (assoc "user" (cadr mount-spec)))))
1329 (domain (tramp-gvfs-dbus-byte-array-to-string
1330 (cadr (assoc "domain" (cadr mount-spec)))))
1331 (host (tramp-gvfs-dbus-byte-array-to-string
1332 (cadr (or (assoc "host" (cadr mount-spec))
1333 (assoc "server" (cadr mount-spec))))))
1334 (port (tramp-gvfs-dbus-byte-array-to-string
1335 (cadr (assoc "port" (cadr mount-spec)))))
1336 (ssl (tramp-gvfs-dbus-byte-array-to-string
1337 (cadr (assoc "ssl" (cadr mount-spec)))))
1339 (tramp-gvfs-dbus-byte-array-to-string
1341 (tramp-gvfs-dbus-byte-array-to-string
1342 (or (cadr (assoc "share" (cadr mount-spec)))
1343 (cadr (assoc "volume" (cadr mount-spec))))))))
1344 (when (string-match "^\\(afp\\|smb\\)" method)
1345 (setq method (match-string 1 method)))
1346 (when (string-equal "obex" method)
1347 (setq host (tramp-bluez-device host)))
1348 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1349 (setq method "davs"))
1350 (unless (zerop (length domain))
1351 (setq user (concat user tramp-prefix-domain-format domain)))
1352 (unless (zerop (length port))
1353 (setq host (concat host tramp-prefix-port-format port)))
1354 (with-parsed-tramp-file-name
1355 (tramp-make-tramp-file-name method user host "") nil
1358 signal-name (tramp-gvfs-stringify-dbus-message mount-info))
1359 (tramp-set-file-property v "/" "list-mounts" 'undef)
1360 (if (string-equal (downcase signal-name) "unmounted")
1361 (tramp-set-file-property v "/" "fuse-mountpoint" nil)
1362 ;; Set prefix, mountpoint and location.
1363 (unless (string-equal prefix "/")
1364 (tramp-set-file-property v "/" "prefix" prefix))
1365 (tramp-set-file-property v "/" "fuse-mountpoint" fuse-mountpoint)
1366 (tramp-set-file-property
1367 v "/" "default-location" default-location)))))))
1369 (when tramp-gvfs-enabled
1370 (dbus-register-signal
1371 :session nil tramp-gvfs-path-mounttracker
1372 tramp-gvfs-interface-mounttracker "mounted"
1373 'tramp-gvfs-handler-mounted-unmounted)
1374 (dbus-register-signal
1375 :session nil tramp-gvfs-path-mounttracker
1376 tramp-gvfs-interface-mounttracker "Mounted"
1377 'tramp-gvfs-handler-mounted-unmounted)
1379 (dbus-register-signal
1380 :session nil tramp-gvfs-path-mounttracker
1381 tramp-gvfs-interface-mounttracker "unmounted"
1382 'tramp-gvfs-handler-mounted-unmounted)
1383 (dbus-register-signal
1384 :session nil tramp-gvfs-path-mounttracker
1385 tramp-gvfs-interface-mounttracker "Unmounted"
1386 'tramp-gvfs-handler-mounted-unmounted))
1388 (defun tramp-gvfs-connection-mounted-p (vec)
1389 "Check, whether the location is already mounted."
1391 (tramp-get-file-property vec "/" "fuse-mountpoint" nil)
1395 (with-tramp-file-property vec "/" "list-mounts"
1396 (with-tramp-dbus-call-method vec t
1397 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1398 tramp-gvfs-interface-mounttracker tramp-gvfs-listmounts))
1400 ;; Jump over the first elements of the mount info. Since there
1401 ;; were changes in the entries, we cannot access dedicated
1403 (while (stringp (car elt)) (setq elt (cdr elt)))
1404 (let* ((fuse-mountpoint (tramp-gvfs-dbus-byte-array-to-string
1406 (mount-spec (caddr elt))
1407 (default-location (tramp-gvfs-dbus-byte-array-to-string
1409 (method (tramp-gvfs-dbus-byte-array-to-string
1410 (cadr (assoc "type" (cadr mount-spec)))))
1411 (user (tramp-gvfs-dbus-byte-array-to-string
1412 (cadr (assoc "user" (cadr mount-spec)))))
1413 (domain (tramp-gvfs-dbus-byte-array-to-string
1414 (cadr (assoc "domain" (cadr mount-spec)))))
1415 (host (tramp-gvfs-dbus-byte-array-to-string
1416 (cadr (or (assoc "host" (cadr mount-spec))
1417 (assoc "server" (cadr mount-spec))))))
1418 (port (tramp-gvfs-dbus-byte-array-to-string
1419 (cadr (assoc "port" (cadr mount-spec)))))
1420 (ssl (tramp-gvfs-dbus-byte-array-to-string
1421 (cadr (assoc "ssl" (cadr mount-spec)))))
1423 (tramp-gvfs-dbus-byte-array-to-string
1425 (tramp-gvfs-dbus-byte-array-to-string
1427 (cadr (assoc "share" (cadr mount-spec)))
1428 (cadr (assoc "volume" (cadr mount-spec))))))))
1429 (when (string-match "^\\(afp\\|smb\\)" method)
1430 (setq method (match-string 1 method)))
1431 (when (string-equal "obex" method)
1432 (setq host (tramp-bluez-device host)))
1433 (when (and (string-equal "dav" method) (string-equal "true" ssl))
1434 (setq method "davs"))
1435 (when (and (string-equal "synce" method) (zerop (length user)))
1436 (setq user (or (tramp-file-name-user vec) "")))
1437 (unless (zerop (length domain))
1438 (setq user (concat user tramp-prefix-domain-format domain)))
1439 (unless (zerop (length port))
1440 (setq host (concat host tramp-prefix-port-format port)))
1442 (string-equal method (tramp-file-name-method vec))
1443 (string-equal user (or (tramp-file-name-user vec) ""))
1444 (string-equal host (tramp-file-name-host vec))
1445 (string-match (concat "^" (regexp-quote prefix))
1446 (tramp-file-name-localname vec)))
1447 ;; Set prefix, mountpoint and location.
1448 (unless (string-equal prefix "/")
1449 (tramp-set-file-property vec "/" "prefix" prefix))
1450 (tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
1451 (tramp-set-file-property vec "/" "default-location" default-location)
1452 (throw 'mounted t)))))))
1454 (defun tramp-gvfs-mount-spec-entry (key value)
1455 "Construct a mount-spec entry to be used in a mount_spec.
1456 It was \"a(say)\", but has changed to \"a{sv})\"."
1457 (if (string-match "^(aya{sv})" tramp-gvfs-mountlocation-signature)
1458 (list :dict-entry key
1459 (list :variant (tramp-gvfs-dbus-string-to-byte-array value)))
1460 (list :struct key (tramp-gvfs-dbus-string-to-byte-array value))))
1462 (defun tramp-gvfs-mount-spec (vec)
1463 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1464 (let* ((method (tramp-file-name-method vec))
1465 (user (tramp-file-name-real-user vec))
1466 (domain (tramp-file-name-domain vec))
1467 (host (tramp-file-name-real-host vec))
1468 (port (tramp-file-name-port vec))
1469 (localname (tramp-file-name-localname vec))
1470 (share (when (string-match "^/?\\([^/]+\\)" localname)
1471 (match-string 1 localname)))
1472 (ssl (when (string-match "^davs" method) "true" "false"))
1476 ((string-equal "smb" method)
1477 (list (tramp-gvfs-mount-spec-entry "type" "smb-share")
1478 (tramp-gvfs-mount-spec-entry "server" host)
1479 (tramp-gvfs-mount-spec-entry "share" share)))
1480 ((string-equal "obex" method)
1481 (list (tramp-gvfs-mount-spec-entry "type" method)
1482 (tramp-gvfs-mount-spec-entry
1483 "host" (concat "[" (tramp-bluez-address host) "]"))))
1484 ((string-match "\\`dav" method)
1485 (list (tramp-gvfs-mount-spec-entry "type" "dav")
1486 (tramp-gvfs-mount-spec-entry "host" host)
1487 (tramp-gvfs-mount-spec-entry "ssl" ssl)))
1488 ((string-equal "afp" method)
1489 (list (tramp-gvfs-mount-spec-entry "type" "afp-volume")
1490 (tramp-gvfs-mount-spec-entry "host" host)
1491 (tramp-gvfs-mount-spec-entry "volume" share)))
1493 (list (tramp-gvfs-mount-spec-entry "type" method)
1494 (tramp-gvfs-mount-spec-entry "host" host))))
1496 (list (tramp-gvfs-mount-spec-entry "user" user)))
1498 (list (tramp-gvfs-mount-spec-entry "domain" domain)))
1500 (list (tramp-gvfs-mount-spec-entry
1501 "port" (number-to-string port))))))
1503 (if (and (string-match "\\`dav" method)
1504 (string-match "^/?[^/]+" localname))
1505 (match-string 0 localname)
1509 `(:struct ,(tramp-gvfs-dbus-string-to-byte-array mount-pref) ,mount-spec)))
1512 ;; Connection functions.
1514 (defun tramp-gvfs-maybe-open-connection (vec)
1515 "Maybe open a connection VEC.
1516 Does not do anything if a connection is already open, but re-opens the
1517 connection if a previous connection has died for some reason."
1518 (tramp-check-proper-method-and-host vec)
1520 ;; We set the file name, in case there are incoming D-Bus signals or
1522 (setq tramp-gvfs-dbus-event-vector vec)
1524 ;; For password handling, we need a process bound to the connection
1525 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1527 (unless (get-buffer-process (tramp-get-connection-buffer vec))
1528 (let ((p (make-network-process
1529 :name (tramp-buffer-name vec)
1530 :buffer (tramp-get-connection-buffer vec)
1531 :server t :host 'local :service t)))
1532 (set-process-query-on-exit-flag p nil)))
1534 (unless (tramp-gvfs-connection-mounted-p vec)
1535 (let* ((method (tramp-file-name-method vec))
1536 (user (tramp-file-name-user vec))
1537 (host (tramp-file-name-host vec))
1538 (localname (tramp-file-name-localname vec))
1540 (tramp-gvfs-object-path
1541 (tramp-make-tramp-file-name method user host ""))))
1543 (when (and (string-equal method "smb")
1544 (string-equal localname "/"))
1545 (tramp-error vec 'file-error "Filename must contain a Windows share"))
1547 (when (and (string-equal method "afp")
1548 (string-equal localname "/"))
1549 (tramp-error vec 'file-error "Filename must contain an AFP volume"))
1551 (with-tramp-progress-reporter
1553 (if (zerop (length user))
1554 (format "Opening connection for %s using %s" host method)
1555 (format "Opening connection for %s@%s using %s" user host method))
1557 ;; Enable `auth-source'.
1558 (tramp-set-connection-property vec "first-password-request" t)
1560 ;; There will be a callback of "askPassword" when a password is
1562 (dbus-register-method
1563 :session dbus-service-emacs object-path
1564 tramp-gvfs-interface-mountoperation "askPassword"
1565 'tramp-gvfs-handler-askpassword)
1566 (dbus-register-method
1567 :session dbus-service-emacs object-path
1568 tramp-gvfs-interface-mountoperation "AskPassword"
1569 'tramp-gvfs-handler-askpassword)
1571 ;; There could be a callback of "askQuestion" when adding fingerprint.
1572 (dbus-register-method
1573 :session dbus-service-emacs object-path
1574 tramp-gvfs-interface-mountoperation "askQuestion"
1575 'tramp-gvfs-handler-askquestion)
1576 (dbus-register-method
1577 :session dbus-service-emacs object-path
1578 tramp-gvfs-interface-mountoperation "AskQuestion"
1579 'tramp-gvfs-handler-askquestion)
1581 ;; The call must be asynchronously, because of the "askPassword"
1582 ;; or "askQuestion"callbacks.
1583 (if (string-match "(so)$" tramp-gvfs-mountlocation-signature)
1584 (with-tramp-dbus-call-method vec nil
1585 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1586 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1587 (tramp-gvfs-mount-spec vec)
1588 `(:struct :string ,(dbus-get-unique-name :session)
1589 :object-path ,object-path))
1590 (with-tramp-dbus-call-method vec nil
1591 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1592 tramp-gvfs-interface-mounttracker tramp-gvfs-mountlocation
1593 (tramp-gvfs-mount-spec vec)
1594 :string (dbus-get-unique-name :session) :object-path object-path))
1596 ;; We must wait, until the mount is applied. This will be
1597 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1600 ((or (tramp-get-method-parameter vec 'tramp-connection-timeout)
1601 tramp-connection-timeout)
1602 (if (zerop (length (tramp-file-name-user vec)))
1605 "Timeout reached mounting %s using %s" host method)
1608 "Timeout reached mounting %s@%s using %s" user host method)))
1609 (while (not (tramp-get-file-property vec "/" "fuse-mountpoint" nil))
1610 (read-event nil nil 0.1)))
1612 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1613 ;; is marked with the fuse-mountpoint "/". We shall react.
1615 (tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
1616 (tramp-error vec 'file-error "FUSE mount denied"))
1618 ;; Mark it as connected.
1619 (tramp-set-connection-property
1620 (tramp-get-connection-process vec) "connected" t))))
1622 ;; In `tramp-check-cached-permissions', the connection properties
1623 ;; {uig,gid}-{integer,string} are used. We set them to their local
1625 (with-tramp-connection-property
1626 vec "uid-integer" (tramp-get-local-uid 'integer))
1627 (with-tramp-connection-property
1628 vec "gid-integer" (tramp-get-local-gid 'integer))
1629 (with-tramp-connection-property
1630 vec "uid-string" (tramp-get-local-uid 'string))
1631 (with-tramp-connection-property
1632 vec "gid-string" (tramp-get-local-gid 'string)))
1634 (defun tramp-gvfs-send-command (vec command &rest args)
1635 "Send the COMMAND with its ARGS to connection VEC.
1636 COMMAND is usually a command from the gvfs-* utilities.
1637 `call-process' is applied, and it returns t if the return code is zero."
1638 (with-current-buffer (tramp-get-connection-buffer vec)
1639 (tramp-gvfs-maybe-open-connection vec)
1641 (zerop (apply 'tramp-call-process vec command nil t nil args))))
1644 ;; D-Bus BLUEZ functions.
1646 (defun tramp-bluez-list-devices ()
1647 "Return all discovered bluetooth devices as list.
1648 Every entry is a list (NAME ADDRESS).
1650 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1651 discovery happened more time before indicated there, a rescan will be
1652 started, which lasts some ten seconds. Otherwise, cached results will
1654 ;; Reset the scanned devices list if time has passed.
1655 (and (integerp tramp-bluez-discover-devices-timeout)
1656 (integerp tramp-bluez-discovery)
1657 (> (tramp-time-diff (current-time) tramp-bluez-discovery)
1658 tramp-bluez-discover-devices-timeout)
1659 (setq tramp-bluez-devices nil))
1661 ;; Rescan if needed.
1662 (unless tramp-bluez-devices
1664 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1665 :system tramp-bluez-service "/"
1666 tramp-bluez-interface-manager "DefaultAdapter")))
1667 (setq tramp-bluez-devices nil
1668 tramp-bluez-discovery t)
1669 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1670 :system tramp-bluez-service object-path
1671 tramp-bluez-interface-adapter "StartDiscovery")
1672 (while tramp-bluez-discovery
1673 (read-event nil nil 0.1))))
1674 (setq tramp-bluez-discovery (current-time))
1675 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-bluez-devices)
1676 tramp-bluez-devices)
1678 (defun tramp-bluez-property-changed (property value)
1679 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1680 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" property value)
1682 ((string-equal property "Discovering")
1684 ;; "Discovering" FALSE means discovery run has been completed.
1685 ;; We stop it, because we don't need another run.
1686 (setq tramp-bluez-discovery nil)
1687 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1688 :system tramp-bluez-service (dbus-event-path-name last-input-event)
1689 tramp-bluez-interface-adapter "StopDiscovery")))))
1691 (when tramp-gvfs-enabled
1692 (dbus-register-signal
1693 :system nil nil tramp-bluez-interface-adapter "PropertyChanged"
1694 'tramp-bluez-property-changed))
1696 (defun tramp-bluez-device-found (device args)
1697 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1698 (tramp-message tramp-gvfs-dbus-event-vector 6 "%s %s" device args)
1699 (let ((alias (car (cadr (assoc "Alias" args))))
1700 (address (car (cadr (assoc "Address" args)))))
1701 ;; Maybe we shall check the device class for being a proper
1702 ;; device, and call also SDP in order to find the obex service.
1703 (add-to-list 'tramp-bluez-devices (list alias address))))
1705 (when tramp-gvfs-enabled
1706 (dbus-register-signal
1707 :system nil nil tramp-bluez-interface-adapter "DeviceFound"
1708 'tramp-bluez-device-found))
1710 (defun tramp-bluez-parse-device-names (_ignore)
1711 "Return a list of (nil host) tuples allowed to access."
1713 (lambda (x) (list nil (car x)))
1714 (tramp-bluez-list-devices)))
1716 ;; Add completion function for OBEX method.
1717 (when (and tramp-gvfs-enabled
1718 (member tramp-bluez-service (dbus-list-known-names :system)))
1719 (tramp-set-completion-function
1720 "obex" '((tramp-bluez-parse-device-names ""))))
1723 ;; D-Bus zeroconf functions.
1725 (defun tramp-zeroconf-parse-device-names (service)
1726 "Return a list of (user host) tuples allowed to access."
1729 (let ((host (zeroconf-service-host x))
1730 (port (zeroconf-service-port x))
1731 (text (zeroconf-service-txt x))
1734 (setq host (format "%s%s%d" host tramp-prefix-port-regexp port)))
1735 ;; A user is marked in a TXT field like "u=guest".
1737 (when (string-match "u=\\(.+\\)$" (car text))
1738 (setq user (match-string 1 (car text))))
1739 (setq text (cdr text)))
1741 (zeroconf-list-services service)))
1743 ;; We use the TRIM argument of `split-string', which exist since Emacs
1744 ;; 24.4. I mask this for older Emacs versions, there is no harm.
1745 (defun tramp-gvfs-parse-device-names (service)
1746 "Return a list of (user host) tuples allowed to access.
1747 This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi."
1750 (tramp-compat-funcall
1752 (shell-command-to-string (format "avahi-browse -trkp %s" service))
1753 "[\n\r]+" 'omit "^\\+;.*$"))))
1757 (let* ((list (split-string x ";"))
1760 (text (tramp-compat-funcall
1761 'split-string (nth 9 list) "\" \"" 'omit "\""))
1763 ; (when (and port (not (string-equal port "0")))
1764 ; (setq host (format "%s%s%s" host tramp-prefix-port-regexp port)))
1765 ;; A user is marked in a TXT field like "u=guest".
1767 (when (string-match "u=\\(.+\\)$" (car text))
1768 (setq user (match-string 1 (car text))))
1769 (setq text (cdr text)))
1773 ;; Add completion functions for AFP, DAV, DAVS, SFTP and SMB methods.
1774 (when tramp-gvfs-enabled
1775 (zeroconf-init tramp-gvfs-zeroconf-domain)
1776 (if (zeroconf-list-service-types)
1778 (tramp-set-completion-function
1779 "afp" '((tramp-zeroconf-parse-device-names "_afpovertcp._tcp")))
1780 (tramp-set-completion-function
1781 "dav" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
1782 (tramp-set-completion-function
1783 "davs" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
1784 (tramp-set-completion-function
1785 "sftp" '((tramp-zeroconf-parse-device-names "_ssh._tcp")
1786 (tramp-zeroconf-parse-device-names "_workstation._tcp")))
1787 (when (member "smb" tramp-gvfs-methods)
1788 (tramp-set-completion-function
1789 "smb" '((tramp-zeroconf-parse-device-names "_smb._tcp")))))
1791 (when (executable-find "avahi-browse")
1792 (tramp-set-completion-function
1793 "afp" '((tramp-gvfs-parse-device-names "_afpovertcp._tcp")))
1794 (tramp-set-completion-function
1795 "dav" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
1796 (tramp-set-completion-function
1797 "davs" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
1798 (tramp-set-completion-function
1799 "sftp" '((tramp-gvfs-parse-device-names "_ssh._tcp")
1800 (tramp-gvfs-parse-device-names "_workstation._tcp")))
1801 (when (member "smb" tramp-gvfs-methods)
1802 (tramp-set-completion-function
1803 "smb" '((tramp-gvfs-parse-device-names "_smb._tcp")))))))
1806 ;; D-Bus SYNCE functions.
1808 (defun tramp-synce-list-devices ()
1809 "Return all discovered synce devices as list.
1810 They are retrieved from the hal daemon."
1811 (let (tramp-synce-devices)
1813 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1814 :system tramp-hal-service tramp-hal-path-manager
1815 tramp-hal-interface-manager "GetAllDevices"))
1816 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1817 :system tramp-hal-service device tramp-hal-interface-device
1818 "PropertyExists" "sync.plugin")
1820 (with-tramp-dbus-call-method
1821 tramp-gvfs-dbus-event-vector t
1822 :system tramp-hal-service device tramp-hal-interface-device
1823 "GetPropertyString" "pda.pocketpc.name")))
1824 (unless (member prop tramp-synce-devices)
1825 (push prop tramp-synce-devices)))))
1826 (tramp-message tramp-gvfs-dbus-event-vector 10 "%s" tramp-synce-devices)
1827 tramp-synce-devices))
1829 (defun tramp-synce-parse-device-names (_ignore)
1830 "Return a list of (nil host) tuples allowed to access."
1832 (lambda (x) (list nil x))
1833 (tramp-synce-list-devices)))
1835 ;; Add completion function for SYNCE method.
1836 (when tramp-gvfs-enabled
1837 (tramp-set-completion-function
1838 "synce" '((tramp-synce-parse-device-names ""))))
1840 (add-hook 'tramp-unload-hook
1842 (unload-feature 'tramp-gvfs 'force)))
1844 (provide 'tramp-gvfs)
1848 ;; * Host name completion via afp-server, smb-server or smb-network.
1849 ;; * Check how two shares of the same SMB server can be mounted in
1851 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1853 ;; * Implement obex for other serial communication but bluetooth.
1855 ;;; tramp-gvfs.el ends here