1 ;;; tramp-gvfs.el --- Tramp access functions for GVFS daemon
3 ;; Copyright (C) 2009, 2010 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.2 (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.2 (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 ;; All actions to mount a remote location, and to retrieve mount
37 ;; information, are performed by D-Bus messages. File operations
38 ;; themselves are performed via the mounted filesystem in ~/.gvfs.
39 ;; Consequently, GNU Emacs 23.1 with enabled D-Bus bindings is a
42 ;; The GVFS D-Bus interface is said to be instable. There are even no
43 ;; introspection data. The interface, as discovered during
44 ;; development time, is given in respective comments.
46 ;; The customer option `tramp-gvfs-methods' contains the list of
47 ;; supported connection methods. Per default, these are "dav",
48 ;; "davs", "obex" and "synce". Note that with "obex" it might be
49 ;; necessary to pair with the other bluetooth device, if it hasn't
50 ;; been done already. There might be also some few seconds delay in
51 ;; discovering available bluetooth devices.
53 ;; Other possible connection methods are "ftp", "sftp" and "smb".
54 ;; When one of these methods is added to the list, the remote access
55 ;; for that method is performed via GVFS instead of the native Tramp
58 ;; GVFS offers even more connection methods. The complete list of
59 ;; connection methods of the actual GVFS implementation can be
67 ;; :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
68 ;; tramp-gvfs-interface-mounttracker "listMountableInfo")))
70 ;; Note that all other connection methods are not tested, beside the
71 ;; ones offered for customization in `tramp-gvfs-methods'. If you
72 ;; request an additional connection method to be supported, please
75 ;; For hostname completion, information is retrieved either from the
76 ;; bluez daemon (for the "obex" method), the hal daemon (for the
77 ;; "synce" method), or from the zeroconf daemon (for the "dav",
78 ;; "davs", and "sftp" methods). The zeroconf daemon is pre-configured
79 ;; to discover services in the "local" domain. If another domain
80 ;; shall be used for discovering services, the customer option
81 ;; `tramp-gvfs-zeroconf-domain' can be set accordingly.
85 ;; * The current GVFS implementation does not allow to write on the
86 ;; remote bluetooth device via OBEX.
88 ;; * Two shares of the same SMB server cannot be mounted in parallel.
92 ;; D-Bus support in the Emacs core can be disabled with configuration
93 ;; option "--without-dbus". Declare used subroutines and variables.
94 (declare-function dbus-call-method
"dbusbind.c")
95 (declare-function dbus-call-method-asynchronously
"dbusbind.c")
96 (declare-function dbus-get-unique-name
"dbusbind.c")
97 (declare-function dbus-register-method
"dbusbind.c")
98 (declare-function dbus-register-signal
"dbusbind.c")
100 ;; Pacify byte-compiler
113 (defcustom tramp-gvfs-methods
'("dav" "davs" "obex" "synce")
114 "*List of methods for remote files, accessed with GVFS."
117 :type
'(repeat (choice (const "dav")
125 ;; Add a default for `tramp-default-user-alist'. Rule: For the SYNCE
126 ;; method, no user is chosen.
127 (add-to-list 'tramp-default-user-alist
'("\\`synce\\'" nil nil
))
129 (defcustom tramp-gvfs-zeroconf-domain
"local"
130 "*Zeroconf domain to be used for discovering services, like host names."
135 ;; Add the methods to `tramp-methods', in order to allow minibuffer
138 (when (featurep 'dbusbind
)
139 (dolist (elt tramp-gvfs-methods
)
140 (unless (assoc elt tramp-methods
)
141 (add-to-list 'tramp-methods
(cons elt nil
)))))
143 (defconst tramp-gvfs-path-tramp
(concat dbus-path-emacs
"/Tramp")
144 "The preceeding object path for own objects.")
146 (defconst tramp-gvfs-service-daemon
"org.gtk.vfs.Daemon"
147 "The well known name of the GVFS daemon.")
149 ;; Check that GVFS is available. D-Bus integration is available since
150 ;; Emacs 23 on some system types. We don't call `dbus-ping', because
151 ;; this would load dbus.el.
152 (unless (and (tramp-compat-funcall 'dbus-get-unique-name
:session
)
153 (tramp-compat-process-running-p "gvfs-fuse-daemon"))
154 (error "Package `tramp-gvfs' not supported"))
156 (defconst tramp-gvfs-path-mounttracker
"/org/gtk/vfs/mounttracker"
157 "The object path of the GVFS daemon.")
159 (defconst tramp-gvfs-interface-mounttracker
"org.gtk.vfs.MountTracker"
160 "The mount tracking interface in the GVFS daemon.")
162 ;; <interface name='org.gtk.vfs.MountTracker'>
163 ;; <method name='listMounts'>
164 ;; <arg name='mount_info_list'
165 ;; type='a{sosssssbay{aya{say}}ay}'
168 ;; <method name='mountLocation'>
169 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
170 ;; <arg name='dbus_id' type='s' direction='in'/>
171 ;; <arg name='object_path' type='o' direction='in'/>
173 ;; <signal name='mounted'>
174 ;; <arg name='mount_info'
175 ;; type='{sosssssbay{aya{say}}ay}'/>
177 ;; <signal name='unmounted'>
178 ;; <arg name='mount_info'
179 ;; type='{sosssssbay{aya{say}}ay}'/>
185 ;; OBJECT_PATH object_path
186 ;; STRING display_name
187 ;; STRING stable_name
188 ;; STRING x_content_types Since GVFS 1.0 only !!!
190 ;; STRING prefered_filename_encoding
191 ;; BOOLEAN user_visible
192 ;; ARRAY BYTE fuse_mountpoint
194 ;; ARRAY BYTE mount_prefix
196 ;; STRUCT mount_spec_item
197 ;; STRING key (server, share, type, user, host, port)
199 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
201 (defconst tramp-gvfs-interface-mountoperation
"org.gtk.vfs.MountOperation"
202 "Used by the dbus-proxying implementation of GMountOperation.")
204 ;; <interface name='org.gtk.vfs.MountOperation'>
205 ;; <method name='askPassword'>
206 ;; <arg name='message' type='s' direction='in'/>
207 ;; <arg name='default_user' type='s' direction='in'/>
208 ;; <arg name='default_domain' type='s' direction='in'/>
209 ;; <arg name='flags' type='u' direction='in'/>
210 ;; <arg name='handled' type='b' direction='out'/>
211 ;; <arg name='aborted' type='b' direction='out'/>
212 ;; <arg name='password' type='s' direction='out'/>
213 ;; <arg name='username' type='s' direction='out'/>
214 ;; <arg name='domain' type='s' direction='out'/>
215 ;; <arg name='anonymous' type='b' direction='out'/>
216 ;; <arg name='password_save' type='u' direction='out'/>
218 ;; <method name='askQuestion'>
219 ;; <arg name='message' type='s' direction='in'/>
220 ;; <arg name='choices' type='as' direction='in'/>
221 ;; <arg name='handled' type='b' direction='out'/>
222 ;; <arg name='aborted' type='b' direction='out'/>
223 ;; <arg name='choice' type='u' direction='out'/>
227 ;; The following flags are used in "askPassword". They are defined in
228 ;; /usr/include/glib-2.0/gio/gioenums.h.
230 (defconst tramp-gvfs-password-need-password
1
231 "Operation requires a password.")
233 (defconst tramp-gvfs-password-need-username
2
234 "Operation requires a username.")
236 (defconst tramp-gvfs-password-need-domain
4
237 "Operation requires a domain.")
239 (defconst tramp-gvfs-password-saving-supported
8
240 "Operation supports saving settings.")
242 (defconst tramp-gvfs-password-anonymous-supported
16
243 "Operation supports anonymous users.")
245 (defconst tramp-bluez-service
"org.bluez"
246 "The well known name of the BLUEZ service.")
248 (defconst tramp-bluez-interface-manager
"org.bluez.Manager"
249 "The manager interface of the BLUEZ daemon.")
251 ;; <interface name='org.bluez.Manager'>
252 ;; <method name='DefaultAdapter'>
253 ;; <arg type='o' direction='out'/>
255 ;; <method name='FindAdapter'>
256 ;; <arg type='s' direction='in'/>
257 ;; <arg type='o' direction='out'/>
259 ;; <method name='ListAdapters'>
260 ;; <arg type='ao' direction='out'/>
262 ;; <signal name='AdapterAdded'>
265 ;; <signal name='AdapterRemoved'>
268 ;; <signal name='DefaultAdapterChanged'>
273 (defconst tramp-bluez-interface-adapter
"org.bluez.Adapter"
274 "The adapter interface of the BLUEZ daemon.")
276 ;; <interface name='org.bluez.Adapter'>
277 ;; <method name='GetProperties'>
278 ;; <arg type='a{sv}' direction='out'/>
280 ;; <method name='SetProperty'>
281 ;; <arg type='s' direction='in'/>
282 ;; <arg type='v' direction='in'/>
284 ;; <method name='RequestMode'>
285 ;; <arg type='s' direction='in'/>
287 ;; <method name='ReleaseMode'/>
288 ;; <method name='RequestSession'/>
289 ;; <method name='ReleaseSession'/>
290 ;; <method name='StartDiscovery'/>
291 ;; <method name='StopDiscovery'/>
292 ;; <method name='ListDevices'>
293 ;; <arg type='ao' direction='out'/>
295 ;; <method name='CreateDevice'>
296 ;; <arg type='s' direction='in'/>
297 ;; <arg type='o' direction='out'/>
299 ;; <method name='CreatePairedDevice'>
300 ;; <arg type='s' direction='in'/>
301 ;; <arg type='o' direction='in'/>
302 ;; <arg type='s' direction='in'/>
303 ;; <arg type='o' direction='out'/>
305 ;; <method name='CancelDeviceCreation'>
306 ;; <arg type='s' direction='in'/>
308 ;; <method name='RemoveDevice'>
309 ;; <arg type='o' direction='in'/>
311 ;; <method name='FindDevice'>
312 ;; <arg type='s' direction='in'/>
313 ;; <arg type='o' direction='out'/>
315 ;; <method name='RegisterAgent'>
316 ;; <arg type='o' direction='in'/>
317 ;; <arg type='s' direction='in'/>
319 ;; <method name='UnregisterAgent'>
320 ;; <arg type='o' direction='in'/>
322 ;; <signal name='DeviceCreated'>
325 ;; <signal name='DeviceRemoved'>
328 ;; <signal name='DeviceFound'>
330 ;; <arg type='a{sv}'/>
332 ;; <signal name='PropertyChanged'>
336 ;; <signal name='DeviceDisappeared'>
341 (defcustom tramp-bluez-discover-devices-timeout
60
342 "Defines seconds since last bluetooth device discovery before rescanning.
343 A value of 0 would require an immediate discovery during hostname
344 completion, nil means to use always cached values for discovered
348 :type
'(choice (const nil
) integer
))
350 (defvar tramp-bluez-discovery nil
351 "Indicator for a running bluetooth device discovery.
352 It keeps the timestamp of last discovery.")
354 (defvar tramp-bluez-devices nil
355 "Alist of detected bluetooth devices.
356 Every entry is a list (NAME ADDRESS).")
358 (defconst tramp-hal-service
"org.freedesktop.Hal"
359 "The well known name of the HAL service.")
361 (defconst tramp-hal-path-manager
"/org/freedesktop/Hal/Manager"
362 "The object path of the HAL daemon manager.")
364 (defconst tramp-hal-interface-manager
"org.freedesktop.Hal.Manager"
365 "The manager interface of the HAL daemon.")
367 (defconst tramp-hal-interface-device
"org.freedesktop.Hal.Device"
368 "The device interface of the HAL daemon.")
371 ;; New handlers should be added here.
372 (defconst tramp-gvfs-file-name-handler-alist
374 (access-file . ignore
)
375 (add-name-to-file . tramp-gvfs-handle-copy-file
)
376 ;; `byte-compiler-base-file-name' performed by default handler.
377 (copy-file . tramp-gvfs-handle-copy-file
)
378 (delete-directory . tramp-gvfs-handle-delete-directory
)
379 (delete-file . tramp-gvfs-handle-delete-file
)
380 ;; `diff-latest-backup-file' performed by default handler.
381 (directory-file-name . tramp-handle-directory-file-name
)
382 (directory-files . tramp-gvfs-handle-directory-files
)
383 (directory-files-and-attributes
384 . tramp-gvfs-handle-directory-files-and-attributes
)
385 (dired-call-process . ignore
)
386 (dired-compress-file . ignore
)
387 (dired-uncache . tramp-handle-dired-uncache
)
388 ;; `executable-find' is not official yet. performed by default handler.
389 (expand-file-name . tramp-gvfs-handle-expand-file-name
)
390 ;; `file-accessible-directory-p' performed by default handler.
391 (file-attributes . tramp-gvfs-handle-file-attributes
)
392 (file-directory-p . tramp-gvfs-handle-file-directory-p
)
393 (file-executable-p . tramp-gvfs-handle-file-executable-p
)
394 (file-exists-p . tramp-gvfs-handle-file-exists-p
)
395 (file-local-copy . tramp-gvfs-handle-file-local-copy
)
396 ;; `file-modes' performed by default handler.
397 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions
)
398 (file-name-as-directory . tramp-handle-file-name-as-directory
)
399 (file-name-completion . tramp-handle-file-name-completion
)
400 (file-name-directory . tramp-handle-file-name-directory
)
401 (file-name-nondirectory . tramp-handle-file-name-nondirectory
)
402 ;; `file-name-sans-versions' performed by default handler.
403 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p
)
404 (file-ownership-preserved-p . ignore
)
405 (file-readable-p . tramp-gvfs-handle-file-readable-p
)
406 (file-regular-p . tramp-handle-file-regular-p
)
407 (file-remote-p . tramp-handle-file-remote-p
)
408 (file-selinux-context . tramp-gvfs-handle-file-selinux-context
)
409 (file-symlink-p . tramp-handle-file-symlink-p
)
410 ;; `file-truename' performed by default handler.
411 (file-writable-p . tramp-gvfs-handle-file-writable-p
)
412 (find-backup-file-name . tramp-handle-find-backup-file-name
)
413 ;; `find-file-noselect' performed by default handler.
414 ;; `get-file-buffer' performed by default handler.
415 (insert-directory . tramp-gvfs-handle-insert-directory
)
416 (insert-file-contents . tramp-gvfs-handle-insert-file-contents
)
417 (load . tramp-handle-load
)
418 (make-directory . tramp-gvfs-handle-make-directory
)
419 (make-directory-internal . ignore
)
420 (make-symbolic-link . ignore
)
421 (process-file . tramp-gvfs-handle-process-file
)
422 (rename-file . tramp-gvfs-handle-rename-file
)
423 (set-file-modes . tramp-gvfs-handle-set-file-modes
)
424 (set-file-selinux-context . tramp-gvfs-handle-set-file-selinux-context
)
425 (set-visited-file-modtime . tramp-gvfs-handle-set-visited-file-modtime
)
426 (shell-command . tramp-gvfs-handle-shell-command
)
427 (start-file-process . tramp-gvfs-handle-start-file-process
)
428 (substitute-in-file-name . tramp-handle-substitute-in-file-name
)
429 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory
)
430 (vc-registered . ignore
)
431 (verify-visited-file-modtime
432 . tramp-gvfs-handle-verify-visited-file-modtime
)
433 (write-region . tramp-gvfs-handle-write-region
)
435 "Alist of handler functions for Tramp GVFS method.
436 Operations not mentioned here will be handled by the default Emacs primitives.")
439 (defsubst tramp-gvfs-file-name-p
(filename)
440 "Check if it's a filename handled by the GVFS daemon."
441 (and (tramp-tramp-file-p filename
)
443 (tramp-file-name-method (tramp-dissect-file-name filename
))))
444 (and (stringp method
) (member method tramp-gvfs-methods
)))))
447 (defun tramp-gvfs-file-name-handler (operation &rest args
)
448 "Invoke the GVFS related OPERATION.
449 First arg specifies the OPERATION, second arg is a list of arguments to
450 pass to the OPERATION."
451 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist
)))
453 (save-match-data (apply (cdr fn
) args
))
454 (tramp-run-real-handler operation args
))))
456 ;; This might be moved to tramp.el. It shall be the first file name
459 (when (featurep 'dbusbind
)
460 (add-to-list 'tramp-foreign-file-name-handler-alist
461 (cons 'tramp-gvfs-file-name-p
'tramp-gvfs-file-name-handler
)))
463 (defun tramp-gvfs-stringify-dbus-message (message)
464 "Convert a D-Bus message into readable UTF8 strings, used for traces."
466 ((and (consp message
) (characterp (car message
)))
467 (format "%S" (dbus-byte-array-to-string message
)))
469 (mapcar 'tramp-gvfs-stringify-dbus-message message
))
471 (format "%S" message
))
474 (defmacro with-tramp-dbus-call-method
475 (vec synchronous bus service path interface method
&rest args
)
476 "Apply a D-Bus call on bus BUS.
478 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
479 it is an asynchronous call, with `ignore' as callback function.
481 The other arguments have the same meaning as with `dbus-call-method'
482 or `dbus-call-method-asynchronously'. Additionally, the call
483 will be traced by Tramp with trace level 6."
484 `(let ((func (if ,synchronous
485 'dbus-call-method
'dbus-call-method-asynchronously
))
486 (args (append (list ,bus
,service
,path
,interface
,method
)
487 (if ,synchronous
(list ,@args
) (list 'ignore
,@args
))))
489 (tramp-message ,vec
6 "%s %s" func args
)
490 (setq result
(apply func args
))
491 (tramp-message ,vec
6 "%s" (tramp-gvfs-stringify-dbus-message result
))
494 (put 'with-tramp-dbus-call-method
'lisp-indent-function
2)
495 (put 'with-tramp-dbus-call-method
'edebug-form-spec
'(form symbolp body
))
496 (tramp-compat-font-lock-add-keywords
497 'emacs-lisp-mode
'("\\<with-tramp-dbus-call-method\\>"))
499 (defmacro with-tramp-gvfs-error-message
(filename handler
&rest args
)
500 "Apply a Tramp GVFS `handler'.
501 In case of an error, modify the error message by replacing
502 `filename' with its GVFS mounted name."
503 `(let ((fuse-file-name (regexp-quote (tramp-gvfs-fuse-file-name ,filename
)))
506 (tramp-compat-funcall ,handler
,@args
)
510 (when (and (stringp (car elt
))
511 (string-match fuse-file-name
(car elt
)))
512 (setcar elt
(replace-match ,filename t t
(car elt
))))
513 (setq elt
(cdr elt
)))
514 (signal (car err
) (cdr err
))))))
516 (put 'with-tramp-gvfs-error-message
'lisp-indent-function
2)
517 (put 'with-tramp-gvfs-error-message
'edebug-form-spec
'(form symbolp body
))
518 (tramp-compat-font-lock-add-keywords
519 'emacs-lisp-mode
'("\\<with-tramp-gvfs-error-message\\>"))
521 (defvar tramp-gvfs-dbus-event-vector nil
522 "Current Tramp file name to be used, as vector.
523 It is needed when D-Bus signals or errors arrive, because there
524 is no information where to trace the message.")
526 (defun tramp-gvfs-dbus-event-error (event err
)
527 "Called when a D-Bus error message arrives, see `dbus-event-error-hooks'."
528 (when tramp-gvfs-dbus-event-vector
529 (tramp-message tramp-gvfs-dbus-event-vector
10 "%S" event
)
530 (tramp-error tramp-gvfs-dbus-event-vector
'file-error
"%s" (cadr err
))))
532 (add-hook 'dbus-event-error-hooks
'tramp-gvfs-dbus-event-error
)
535 ;; File name primitives.
537 (defun tramp-gvfs-handle-copy-file
538 (filename newname
&optional ok-if-already-exists keep-date
539 preserve-uid-gid preserve-selinux-context
)
540 "Like `copy-file' for Tramp files."
541 (with-parsed-tramp-file-name
542 (if (tramp-tramp-file-p filename
) filename newname
) nil
543 (with-progress-reporter
544 v
0 (format "Copying %s to %s" filename newname
)
548 (if (tramp-gvfs-file-name-p filename
)
549 (tramp-gvfs-fuse-file-name filename
)
551 (if (tramp-gvfs-file-name-p newname
)
552 (tramp-gvfs-fuse-file-name newname
)
554 ok-if-already-exists keep-date preserve-uid-gid
)))
555 (when preserve-selinux-context
556 (setq args
(append args
(list preserve-selinux-context
))))
557 (apply 'copy-file args
))
559 ;; Error case. Let's try it with the GVFS utilities.
561 (tramp-message v
4 "`copy-file' failed, trying `gvfs-copy'")
565 (append (if (or keep-date preserve-uid-gid
)
569 (tramp-gvfs-url-file-name filename
)
570 (tramp-gvfs-url-file-name newname
)))))
571 (apply 'tramp-gvfs-send-command v
"gvfs-copy" args
)))
572 ;; Propagate the error.
573 (tramp-error v
(car err
) "%s" (cdr err
)))))))
575 (when (file-remote-p newname
)
576 (with-parsed-tramp-file-name newname nil
577 (tramp-flush-file-property v
(file-name-directory localname
))
578 (tramp-flush-file-property v localname
))))
580 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive
)
581 "Like `delete-directory' for Tramp files."
582 (tramp-compat-delete-directory
583 (tramp-gvfs-fuse-file-name directory
) recursive
))
585 (defun tramp-gvfs-handle-delete-file (filename &optional trash
)
586 "Like `delete-file' for Tramp files."
587 (tramp-compat-delete-file (tramp-gvfs-fuse-file-name filename
) trash
))
589 (defun tramp-gvfs-handle-directory-files
590 (directory &optional full match nosort
)
591 "Like `directory-files' for Tramp files."
592 (let ((fuse-file-name (tramp-gvfs-fuse-file-name directory
)))
595 (if (string-match fuse-file-name x
)
596 (replace-match directory t t x
)
598 (directory-files fuse-file-name full match nosort
))))
600 (defun tramp-gvfs-handle-directory-files-and-attributes
601 (directory &optional full match nosort id-format
)
602 "Like `directory-files-and-attributes' for Tramp files."
603 (let ((fuse-file-name (tramp-gvfs-fuse-file-name directory
)))
606 (when (string-match fuse-file-name
(car x
))
607 (setcar x
(replace-match directory t t
(car x
))))
609 (directory-files-and-attributes
610 fuse-file-name full match nosort id-format
))))
612 (defun tramp-gvfs-handle-expand-file-name (name &optional dir
)
613 "Like `expand-file-name' for Tramp files."
614 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
615 (setq dir
(or dir default-directory
"/"))
616 ;; Unless NAME is absolute, concat DIR and NAME.
617 (unless (file-name-absolute-p name
)
618 (setq name
(concat (file-name-as-directory dir
) name
)))
619 ;; If NAME is not a Tramp file, run the real handler.
620 (if (not (tramp-tramp-file-p name
))
621 (tramp-run-real-handler 'expand-file-name
(list name nil
))
623 (with-parsed-tramp-file-name name nil
624 ;; If there is a default location, expand tilde.
625 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname
)
627 (tramp-gvfs-maybe-open-connection (vector method user host
"/")))
630 (tramp-get-file-property v
"/" "default-location" "~")
632 ;; Tilde expansion is not possible.
633 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname
)
636 "Cannot expand tilde in file `%s'" name
))
637 (unless (tramp-run-real-handler 'file-name-absolute-p
(list localname
))
638 (setq localname
(concat "/" localname
)))
639 ;; We do not pass "/..".
640 (if (string-equal "smb" method
)
641 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname
)
642 (setq localname
(replace-match "/" t t localname
1)))
643 (when (string-match "^/\\.\\./?" localname
)
644 (setq localname
(replace-match "/" t t localname
))))
645 ;; There might be a double slash. Remove this.
646 (while (string-match "//" localname
)
647 (setq localname
(replace-match "/" t t localname
)))
648 ;; No tilde characters in file name, do normal
649 ;; `expand-file-name' (this does "/./" and "/../").
650 (tramp-make-tramp-file-name
652 (tramp-run-real-handler
653 'expand-file-name
(list localname
))))))
655 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format
)
656 "Like `file-attributes' for Tramp files."
657 (file-attributes (tramp-gvfs-fuse-file-name filename
) id-format
))
659 (defun tramp-gvfs-handle-file-directory-p (filename)
660 "Like `file-directory-p' for Tramp files."
661 (file-directory-p (tramp-gvfs-fuse-file-name filename
)))
663 (defun tramp-gvfs-handle-file-executable-p (filename)
664 "Like `file-executable-p' for Tramp files."
665 (file-executable-p (tramp-gvfs-fuse-file-name filename
)))
667 (defun tramp-gvfs-handle-file-exists-p (filename)
668 "Like `file-exists-p' for Tramp files."
669 (file-exists-p (tramp-gvfs-fuse-file-name filename
)))
671 (defun tramp-gvfs-handle-file-local-copy (filename)
672 "Like `file-local-copy' for Tramp files."
673 (with-parsed-tramp-file-name filename nil
674 (let ((tmpfile (tramp-compat-make-temp-file filename
)))
675 (unless (file-exists-p filename
)
678 "Cannot make local copy of non-existing file `%s'" filename
))
679 (copy-file filename tmpfile t t
)
682 (defun tramp-gvfs-handle-file-name-all-completions (filename directory
)
683 "Like `file-name-all-completions' for Tramp files."
684 (unless (save-match-data (string-match "/" filename
))
685 (file-name-all-completions filename
(tramp-gvfs-fuse-file-name directory
))))
687 (defun tramp-gvfs-handle-file-readable-p (filename)
688 "Like `file-readable-p' for Tramp files."
689 (file-readable-p (tramp-gvfs-fuse-file-name filename
)))
691 (defun tramp-gvfs-handle-file-selinux-context (filename)
692 "Like `file-selinux-context' for Tramp files."
693 (tramp-compat-funcall
694 'file-selinux-context
(tramp-gvfs-fuse-file-name filename
)))
696 (defun tramp-gvfs-handle-file-writable-p (filename)
697 "Like `file-writable-p' for Tramp files."
698 (file-writable-p (tramp-gvfs-fuse-file-name filename
)))
700 (defun tramp-gvfs-handle-insert-directory
701 (filename switches
&optional wildcard full-directory-p
)
702 "Like `insert-directory' for Tramp files."
704 (tramp-gvfs-fuse-file-name filename
) switches wildcard full-directory-p
))
706 (defun tramp-gvfs-handle-insert-file-contents
707 (filename &optional visit beg end replace
)
708 "Like `insert-file-contents' for Tramp files."
710 (let ((fuse-file-name (tramp-gvfs-fuse-file-name filename
))
712 (insert-file-contents
713 (tramp-gvfs-fuse-file-name filename
) visit beg end replace
)))
714 (when (string-match fuse-file-name
(car result
))
715 (setcar result
(replace-match filename t t
(car result
))))
717 (setq buffer-file-name filename
)))
719 (defun tramp-gvfs-handle-make-directory (dir &optional parents
)
720 "Like `make-directory' for Tramp files."
721 (with-parsed-tramp-file-name dir nil
723 (with-tramp-gvfs-error-message dir
'make-directory
724 (tramp-gvfs-fuse-file-name dir
) parents
)
726 ;; Error case. Let's try it with the GVFS utilities.
728 (tramp-message v
4 "`make-directory' failed, trying `gvfs-mkdir'")
731 (tramp-gvfs-send-command
732 v
"gvfs-mkdir" (tramp-gvfs-url-file-name dir
)))
733 ;; Propagate the error.
734 (tramp-error v
(car err
) "%s" (cdr err
)))))))
736 (defun tramp-gvfs-handle-process-file
737 (program &optional infile destination display
&rest args
)
738 "Like `process-file' for Tramp files."
739 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory
)))
740 (apply 'call-process program infile destination display args
)))
742 (defun tramp-gvfs-handle-rename-file
743 (filename newname
&optional ok-if-already-exists
)
744 "Like `rename-file' for Tramp files."
745 (with-parsed-tramp-file-name
746 (if (tramp-tramp-file-p filename
) filename newname
) nil
747 (with-progress-reporter
748 v
0 (format "Renaming %s to %s" filename newname
)
751 (if (tramp-gvfs-file-name-p filename
)
752 (tramp-gvfs-fuse-file-name filename
)
754 (if (tramp-gvfs-file-name-p newname
)
755 (tramp-gvfs-fuse-file-name newname
)
757 ok-if-already-exists
)
759 ;; Error case. Let's try it with the GVFS utilities.
761 (tramp-message v
4 "`rename-file' failed, trying `gvfs-move'")
764 (tramp-gvfs-send-command
766 (tramp-gvfs-url-file-name filename
)
767 (tramp-gvfs-url-file-name newname
)))
768 ;; Propagate the error.
769 (tramp-error v
(car err
) "%s" (cdr err
)))))))
771 (when (file-remote-p filename
)
772 (with-parsed-tramp-file-name filename nil
773 (tramp-flush-file-property v
(file-name-directory localname
))
774 (tramp-flush-file-property v localname
)))
776 (when (file-remote-p newname
)
777 (with-parsed-tramp-file-name newname nil
778 (tramp-flush-file-property v
(file-name-directory localname
))
779 (tramp-flush-file-property v localname
))))
781 (defun tramp-gvfs-handle-set-file-modes (filename mode
)
782 "Like `set-file-modes' for Tramp files."
783 (with-tramp-gvfs-error-message filename
'set-file-modes
784 (tramp-gvfs-fuse-file-name filename
) mode
))
786 (defun tramp-gvfs-handle-set-file-selinux-context (filename context
)
787 "Like `set-file-selinux-context' for Tramp files."
788 (with-tramp-gvfs-error-message filename
'set-file-selinux-context
789 (tramp-gvfs-fuse-file-name filename
) context
))
791 (defun tramp-gvfs-handle-set-visited-file-modtime (&optional time-list
)
792 "Like `set-visited-file-modtime' for Tramp files."
793 (let ((buffer-file-name (tramp-gvfs-fuse-file-name (buffer-file-name))))
794 (set-visited-file-modtime time-list
)))
796 (defun tramp-gvfs-handle-shell-command
797 (command &optional output-buffer error-buffer
)
798 "Like `shell-command' for Tramp files."
799 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory
)))
800 (shell-command command output-buffer error-buffer
)))
802 (defun tramp-gvfs-handle-start-file-process (name buffer program
&rest args
)
803 "Like `start-file-process' for Tramp files."
804 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory
)))
805 (apply 'start-process name buffer program args
)))
807 (defun tramp-gvfs-handle-verify-visited-file-modtime (buf)
808 "Like `verify-visited-file-modtime' for Tramp files."
809 (with-current-buffer buf
810 (let ((buffer-file-name (tramp-gvfs-fuse-file-name (buffer-file-name))))
811 (verify-visited-file-modtime buf
))))
813 (defun tramp-gvfs-handle-write-region
814 (start end filename
&optional append visit lockname confirm
)
815 "Like `write-region' for Tramp files."
816 (with-parsed-tramp-file-name filename nil
818 (with-tramp-gvfs-error-message filename
'write-region
819 start end
(tramp-gvfs-fuse-file-name filename
)
820 append visit lockname confirm
)
822 ;; Error case. Let's try rename.
824 (let ((tmpfile (tramp-compat-make-temp-file filename
)))
825 (tramp-message v
4 "`write-region' failed, trying `rename-file'")
826 (write-region start end tmpfile
)
828 (rename-file tmpfile filename
)
830 (delete-file tmpfile
)
831 (tramp-error v
(car err
) "%s" (cdr err
)))))))
833 ;; Set file modification time.
834 (when (or (eq visit t
) (stringp visit
))
835 (set-visited-file-modtime (nth 5 (file-attributes filename
))))
838 (when (or (eq visit t
) (null visit
) (stringp visit
))
839 (tramp-message v
0 "Wrote %s" filename
))
840 (run-hooks 'tramp-handle-write-region-hook
)))
843 ;; File name conversions.
845 (defun tramp-gvfs-url-file-name (filename)
846 "Return FILENAME in URL syntax."
847 ;; "/" must NOT be hexlified.
848 (let ((url-unreserved-chars (append '(?
/) url-unreserved-chars
)))
850 (if (tramp-tramp-file-p filename
)
851 (with-parsed-tramp-file-name (file-truename filename
) nil
852 (when (string-match tramp-user-with-domain-regexp user
)
854 (concat (match-string 2 user
) ";" (match-string 2 user
))))
855 (url-parse-make-urlobj
857 (tramp-file-name-real-host v
) (tramp-file-name-port v
)
858 (url-hexify-string localname
)))
859 (url-parse-make-urlobj
860 "file" nil nil nil nil
(url-hexify-string (file-truename filename
)))))))
862 (defun tramp-gvfs-object-path (filename)
863 "Create a D-Bus object path from FILENAME."
864 (expand-file-name (dbus-escape-as-identifier filename
) tramp-gvfs-path-tramp
))
866 (defun tramp-gvfs-file-name (object-path)
867 "Retrieve file name from D-Bus OBJECT-PATH."
868 (dbus-unescape-from-identifier
869 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path
)))
871 (defun tramp-gvfs-fuse-file-name (filename)
872 "Return FUSE file name, which is directly accessible."
873 (with-parsed-tramp-file-name (expand-file-name filename
) nil
874 (tramp-gvfs-maybe-open-connection v
)
875 (let ((prefix (tramp-get-file-property v
"/" "prefix" ""))
877 (tramp-get-file-property v
"/" "fuse-mountpoint" nil
)))
878 (unless fuse-mountpoint
880 v
'file-error
"There is no FUSE mount point for `%s'" filename
))
881 ;; We must hide the prefix, if any.
882 (when (string-match (concat "^" (regexp-quote prefix
)) localname
)
883 (setq localname
(replace-match "" t t localname
)))
885 v
10 "remote file `%s' is local file `%s'"
886 filename
(concat fuse-mountpoint localname
))
887 (concat fuse-mountpoint localname
))))
889 (defun tramp-bluez-address (device)
890 "Return bluetooth device address from a given bluetooth DEVICE name."
891 (when (stringp device
)
892 (if (string-match tramp-ipv6-regexp device
)
893 (match-string 0 device
)
894 (cadr (assoc device
(tramp-bluez-list-devices))))))
896 (defun tramp-bluez-device (address)
897 "Return bluetooth device name from a given bluetooth device ADDRESS.
898 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
899 (when (stringp address
)
900 (while (string-match "[][]" address
)
901 (setq address
(replace-match "" t t address
)))
903 (dolist (item (tramp-bluez-list-devices) result
)
904 (when (string-match address
(cadr item
))
905 (setq result
(car item
)))))))
908 ;; D-Bus GVFS functions.
910 (defun tramp-gvfs-handler-askpassword (message user domain flags
)
911 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
913 (tramp-gvfs-file-name (dbus-event-path-name last-input-event
)))
917 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message
)
918 (capitalize (match-string 1 message
))
924 (with-parsed-tramp-file-name filename l
925 (when (and (zerop (length user
))
927 (zerop (logand flags tramp-gvfs-password-need-username
))))
928 (setq user
(read-string "User name: ")))
929 (when (and (zerop (length domain
))
930 (not (zerop (logand flags tramp-gvfs-password-need-domain
))))
931 (setq domain
(read-string "Domain name: ")))
933 (tramp-message l
6 "%S %S %S %d" message user domain flags
)
934 (setq tramp-current-method l-method
935 tramp-current-user user
936 tramp-current-host l-host
937 password
(tramp-read-passwd
938 (tramp-get-connection-process l
) pw-prompt
))
941 (if (stringp password
)
943 t
;; password handled.
944 nil
;; no abort of D-Bus.
946 (tramp-file-name-real-user l
)
948 nil
;; not anonymous.
949 0) ;; no password save.
950 ;; No password provided.
951 (list nil t
"" (tramp-file-name-real-user l
) domain nil
0)))
953 ;; When QUIT is raised, we shall return this information to D-Bus.
954 (quit (list nil t
"" "" "" nil
0)))))
956 (defun tramp-gvfs-handler-askquestion (message choices
)
957 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
958 (save-window-excursion
959 (let ((enable-recursive-minibuffers t
)
963 (with-parsed-tramp-file-name
964 (tramp-gvfs-file-name (dbus-event-path-name last-input-event
)) nil
965 (tramp-message v
6 "%S %S" message choices
)
967 ;; In theory, there can be several choices. Until now,
968 ;; there is only the question whether to accept an unknown
971 ;; Preserve message for `progress-reporter'.
972 (tramp-compat-with-temp-message ""
974 (pop-to-buffer (current-buffer))
975 (setq choice
(if (yes-or-no-p (concat (car choices
) " ")) 0 1))
976 (tramp-message v
6 "%d" choice
)))
978 ;; When the choice is "no", we set a dummy fuse-mountpoint
979 ;; in order to leave the timeout.
980 (unless (zerop choice
)
981 (tramp-set-file-property v
"/" "fuse-mountpoint" "/"))
985 nil
;; no abort of D-Bus.
988 ;; When QUIT is raised, we shall return this information to D-Bus.
989 (quit (list nil t
0))))))
991 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
992 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
993 \"org.gtk.vfs.MountTracker.unmounted\" signals."
995 (let ((signal-name (dbus-event-member-name last-input-event
))
997 ;; Jump over the first elements of the mount info. Since there
998 ;; were changes in the antries, we cannot access dedicated
1000 (while (stringp (car elt
)) (setq elt
(cdr elt
)))
1001 (let* ((fuse-mountpoint (dbus-byte-array-to-string (cadr elt
)))
1002 (mount-spec (caddr elt
))
1003 (default-location (dbus-byte-array-to-string (cadddr elt
)))
1004 (method (dbus-byte-array-to-string
1005 (cadr (assoc "type" (cadr mount-spec
)))))
1006 (user (dbus-byte-array-to-string
1007 (cadr (assoc "user" (cadr mount-spec
)))))
1008 (domain (dbus-byte-array-to-string
1009 (cadr (assoc "domain" (cadr mount-spec
)))))
1010 (host (dbus-byte-array-to-string
1011 (cadr (or (assoc "host" (cadr mount-spec
))
1012 (assoc "server" (cadr mount-spec
))))))
1013 (port (dbus-byte-array-to-string
1014 (cadr (assoc "port" (cadr mount-spec
)))))
1015 (ssl (dbus-byte-array-to-string
1016 (cadr (assoc "ssl" (cadr mount-spec
)))))
1017 (prefix (concat (dbus-byte-array-to-string (car mount-spec
))
1018 (dbus-byte-array-to-string
1019 (cadr (assoc "share" (cadr mount-spec
)))))))
1020 (when (string-match "^smb" method
)
1021 (setq method
"smb"))
1022 (when (string-equal "obex" method
)
1023 (setq host
(tramp-bluez-device host
)))
1024 (when (and (string-equal "dav" method
) (string-equal "true" ssl
))
1025 (setq method
"davs"))
1026 (unless (zerop (length domain
))
1027 (setq user
(concat user tramp-prefix-domain-format domain
)))
1028 (unless (zerop (length port
))
1029 (setq host
(concat host tramp-prefix-port-format port
)))
1030 (with-parsed-tramp-file-name
1031 (tramp-make-tramp-file-name method user host
"") nil
1034 signal-name
(tramp-gvfs-stringify-dbus-message mount-info
))
1035 (tramp-set-file-property v
"/" "list-mounts" 'undef
)
1036 (if (string-equal signal-name
"unmounted")
1037 (tramp-set-file-property v
"/" "fuse-mountpoint" nil
)
1038 ;; Set prefix, mountpoint and location.
1039 (unless (string-equal prefix
"/")
1040 (tramp-set-file-property v
"/" "prefix" prefix
))
1041 (tramp-set-file-property v
"/" "fuse-mountpoint" fuse-mountpoint
)
1042 (tramp-set-file-property
1043 v
"/" "default-location" default-location
)))))))
1045 (dbus-register-signal
1046 :session nil tramp-gvfs-path-mounttracker
1047 tramp-gvfs-interface-mounttracker
"mounted"
1048 'tramp-gvfs-handler-mounted-unmounted
)
1050 (dbus-register-signal
1051 :session nil tramp-gvfs-path-mounttracker
1052 tramp-gvfs-interface-mounttracker
"unmounted"
1053 'tramp-gvfs-handler-mounted-unmounted
)
1055 (defun tramp-gvfs-connection-mounted-p (vec)
1056 "Check, whether the location is already mounted."
1058 (tramp-get-file-property vec
"/" "fuse-mountpoint" nil
)
1062 (with-file-property vec
"/" "list-mounts"
1063 (with-tramp-dbus-call-method vec t
1064 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1065 tramp-gvfs-interface-mounttracker
"listMounts"))
1067 ;; Jump over the first elements of the mount info. Since there
1068 ;; were changes in the antries, we cannot access dedicated
1070 (while (stringp (car elt
)) (setq elt
(cdr elt
)))
1071 (let* ((fuse-mountpoint (dbus-byte-array-to-string (cadr elt
)))
1072 (mount-spec (caddr elt
))
1073 (default-location (dbus-byte-array-to-string (cadddr elt
)))
1074 (method (dbus-byte-array-to-string
1075 (cadr (assoc "type" (cadr mount-spec
)))))
1076 (user (dbus-byte-array-to-string
1077 (cadr (assoc "user" (cadr mount-spec
)))))
1078 (domain (dbus-byte-array-to-string
1079 (cadr (assoc "domain" (cadr mount-spec
)))))
1080 (host (dbus-byte-array-to-string
1081 (cadr (or (assoc "host" (cadr mount-spec
))
1082 (assoc "server" (cadr mount-spec
))))))
1083 (port (dbus-byte-array-to-string
1084 (cadr (assoc "port" (cadr mount-spec
)))))
1085 (ssl (dbus-byte-array-to-string
1086 (cadr (assoc "ssl" (cadr mount-spec
)))))
1087 (prefix (concat (dbus-byte-array-to-string (car mount-spec
))
1088 (dbus-byte-array-to-string
1089 (cadr (assoc "share" (cadr mount-spec
)))))))
1090 (when (string-match "^smb" method
)
1091 (setq method
"smb"))
1092 (when (string-equal "obex" method
)
1093 (setq host
(tramp-bluez-device host
)))
1094 (when (and (string-equal "dav" method
) (string-equal "true" ssl
))
1095 (setq method
"davs"))
1096 (when (and (string-equal "synce" method
) (zerop (length user
)))
1097 (setq user
(or (tramp-file-name-user vec
) "")))
1098 (unless (zerop (length domain
))
1099 (setq user
(concat user tramp-prefix-domain-format domain
)))
1100 (unless (zerop (length port
))
1101 (setq host
(concat host tramp-prefix-port-format port
)))
1103 (string-equal method
(tramp-file-name-method vec
))
1104 (string-equal user
(or (tramp-file-name-user vec
) ""))
1105 (string-equal host
(tramp-file-name-host vec
))
1106 (string-match (concat "^" (regexp-quote prefix
))
1107 (tramp-file-name-localname vec
)))
1108 ;; Set prefix, mountpoint and location.
1109 (unless (string-equal prefix
"/")
1110 (tramp-set-file-property vec
"/" "prefix" prefix
))
1111 (tramp-set-file-property vec
"/" "fuse-mountpoint" fuse-mountpoint
)
1112 (tramp-set-file-property vec
"/" "default-location" default-location
)
1113 (throw 'mounted t
)))))))
1115 (defun tramp-gvfs-mount-spec (vec)
1116 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1117 (let* ((method (tramp-file-name-method vec
))
1118 (user (tramp-file-name-real-user vec
))
1119 (domain (tramp-file-name-domain vec
))
1120 (host (tramp-file-name-real-host vec
))
1121 (port (tramp-file-name-port vec
))
1122 (localname (tramp-file-name-localname vec
))
1123 (ssl (if (string-match "^davs" method
) "true" "false"))
1124 (mount-spec '(:array
))
1132 ((string-equal "smb" method
)
1133 (string-match "^/?\\([^/]+\\)" localname
)
1134 `((:struct
"type" ,(dbus-string-to-byte-array "smb-share"))
1135 (:struct
"server" ,(dbus-string-to-byte-array host
))
1136 (:struct
"share" ,(dbus-string-to-byte-array
1137 (match-string 1 localname
)))))
1138 ((string-equal "obex" method
)
1139 `((:struct
"type" ,(dbus-string-to-byte-array method
))
1140 (:struct
"host" ,(dbus-string-to-byte-array
1141 (concat "[" (tramp-bluez-address host
) "]")))))
1142 ((string-match "^dav" method
)
1143 `((:struct
"type" ,(dbus-string-to-byte-array "dav"))
1144 (:struct
"host" ,(dbus-string-to-byte-array host
))
1145 (:struct
"ssl" ,(dbus-string-to-byte-array ssl
))))
1147 `((:struct
"type" ,(dbus-string-to-byte-array method
))
1148 (:struct
"host" ,(dbus-string-to-byte-array host
)))))))
1153 `(:struct
"user" ,(dbus-string-to-byte-array user
))
1159 `(:struct
"domain" ,(dbus-string-to-byte-array domain
))
1165 `(:struct
"port" ,(dbus-string-to-byte-array (number-to-string port
)))
1168 (when (and (string-match "^dav" method
)
1169 (string-match "^/?[^/]+" localname
))
1170 (setq mount-pref
(match-string 0 localname
)))
1173 `(:struct
,(dbus-string-to-byte-array mount-pref
) ,mount-spec
)))
1176 ;; Connection functions
1178 (defun tramp-gvfs-maybe-open-connection (vec)
1179 "Maybe open a connection VEC.
1180 Does not do anything if a connection is already open, but re-opens the
1181 connection if a previous connection has died for some reason."
1183 ;; We set the file name, in case there are incoming D-Bus signals or
1185 (setq tramp-gvfs-dbus-event-vector vec
)
1187 ;; For password handling, we need a process bound to the connection
1188 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1190 (unless (get-buffer-process (tramp-get-buffer vec
))
1191 (let ((p (make-network-process
1192 :name
(tramp-buffer-name vec
)
1193 :buffer
(tramp-get-buffer vec
)
1194 :server t
:host
'local
:service t
)))
1195 (tramp-compat-set-process-query-on-exit-flag p nil
)))
1197 (unless (tramp-gvfs-connection-mounted-p vec
)
1198 (let* ((method (tramp-file-name-method vec
))
1199 (user (tramp-file-name-user vec
))
1200 (host (tramp-file-name-host vec
))
1202 (tramp-gvfs-object-path
1203 (tramp-make-tramp-file-name method user host
""))))
1205 (with-progress-reporter
1207 (if (zerop (length user
))
1208 (format "Opening connection for %s using %s" host method
)
1209 (format "Opening connection for %s@%s using %s" user host method
))
1211 ;; Enable auth-sorce and password-cache.
1212 (tramp-set-connection-property vec
"first-password-request" t
)
1214 ;; There will be a callback of "askPassword", when a password is
1216 (dbus-register-method
1217 :session dbus-service-emacs object-path
1218 tramp-gvfs-interface-mountoperation
"askPassword"
1219 'tramp-gvfs-handler-askpassword
)
1221 ;; There could be a callback of "askQuestion", when adding fingerprint.
1222 (dbus-register-method
1223 :session dbus-service-emacs object-path
1224 tramp-gvfs-interface-mountoperation
"askQuestion"
1225 'tramp-gvfs-handler-askquestion
)
1227 ;; The call must be asynchronously, because of the "askPassword"
1228 ;; or "askQuestion"callbacks.
1229 (with-tramp-dbus-call-method vec nil
1230 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1231 tramp-gvfs-interface-mounttracker
"mountLocation"
1232 (tramp-gvfs-mount-spec vec
) (dbus-get-unique-name :session
)
1233 :object-path object-path
)
1235 ;; We must wait, until the mount is applied. This will be
1236 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1240 (if (zerop (length (tramp-file-name-user vec
)))
1243 "Timeout reached mounting %s using %s" host method
)
1246 "Timeout reached mounting %s@%s using %s" user host method
)))
1247 (while (not (tramp-get-file-property vec
"/" "fuse-mountpoint" nil
))
1248 (read-event nil nil
0.1)))
1250 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1251 ;; is marked with the fuse-mountpoint "/". We shall react.
1253 (tramp-get-file-property vec
"/" "fuse-mountpoint" "") "/")
1254 (tramp-error vec
'file-error
"FUSE mount denied"))
1256 ;; We set the connection property "started" in order to put the
1257 ;; remote location into the cache, which is helpful for further
1259 (tramp-set-connection-property vec
"started" t
)))))
1261 (defun tramp-gvfs-send-command (vec command
&rest args
)
1262 "Send the COMMAND with its ARGS to connection VEC.
1263 COMMAND is usually a command from the gvfs-* utilities.
1264 `call-process' is applied, and its return code is returned."
1266 (with-current-buffer (tramp-get-buffer vec
)
1268 (tramp-message vec
6 "%s %s" command
(mapconcat 'identity args
" "))
1269 (setq result
(apply 'tramp-local-call-process command nil t nil args
))
1270 (tramp-message vec
6 "%s" (buffer-string))
1274 ;; D-Bus BLUEZ functions.
1276 (defun tramp-bluez-list-devices ()
1277 "Return all discovered bluetooth devices as list.
1278 Every entry is a list (NAME ADDRESS).
1280 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1281 discovery happened more time before indicated there, a rescan will be
1282 started, which lasts some ten seconds. Otherwise, cached results will
1284 ;; Reset the scanned devices list if time has passed.
1285 (and (integerp tramp-bluez-discover-devices-timeout
)
1286 (integerp tramp-bluez-discovery
)
1287 (> (tramp-time-diff (current-time) tramp-bluez-discovery
)
1288 tramp-bluez-discover-devices-timeout
)
1289 (setq tramp-bluez-devices nil
))
1291 ;; Rescan if needed.
1292 (unless tramp-bluez-devices
1294 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1295 :system tramp-bluez-service
"/"
1296 tramp-bluez-interface-manager
"DefaultAdapter")))
1297 (setq tramp-bluez-devices nil
1298 tramp-bluez-discovery t
)
1299 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1300 :system tramp-bluez-service object-path
1301 tramp-bluez-interface-adapter
"StartDiscovery")
1302 (while tramp-bluez-discovery
1303 (read-event nil nil
0.1))))
1304 (setq tramp-bluez-discovery
(current-time))
1305 (tramp-message tramp-gvfs-dbus-event-vector
10 "%s" tramp-bluez-devices
)
1306 tramp-bluez-devices
)
1308 (defun tramp-bluez-property-changed (property value
)
1309 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1310 (tramp-message tramp-gvfs-dbus-event-vector
6 "%s %s" property value
)
1312 ((string-equal property
"Discovering")
1314 ;; "Discovering" FALSE means discovery run has been completed.
1315 ;; We stop it, because we don't need another run.
1316 (setq tramp-bluez-discovery nil
)
1317 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1318 :system tramp-bluez-service
(dbus-event-path-name last-input-event
)
1319 tramp-bluez-interface-adapter
"StopDiscovery")))))
1321 (dbus-register-signal
1322 :system nil nil tramp-bluez-interface-adapter
"PropertyChanged"
1323 'tramp-bluez-property-changed
)
1325 (defun tramp-bluez-device-found (device args
)
1326 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1327 (tramp-message tramp-gvfs-dbus-event-vector
6 "%s %s" device args
)
1328 (let ((alias (car (cadr (assoc "Alias" args
))))
1329 (address (car (cadr (assoc "Address" args
)))))
1330 ;; Maybe we shall check the device class for being a proper
1331 ;; device, and call also SDP in order to find the obex service.
1332 (add-to-list 'tramp-bluez-devices
(list alias address
))))
1334 (dbus-register-signal
1335 :system nil nil tramp-bluez-interface-adapter
"DeviceFound"
1336 'tramp-bluez-device-found
)
1338 (defun tramp-bluez-parse-device-names (ignore)
1339 "Return a list of (nil host) tuples allowed to access."
1341 (lambda (x) (list nil
(car x
)))
1342 (tramp-bluez-list-devices)))
1344 ;; Add completion function for OBEX method.
1345 (when (member tramp-bluez-service
(dbus-list-known-names :system
))
1346 (tramp-set-completion-function
1347 "obex" '((tramp-bluez-parse-device-names ""))))
1350 ;; D-Bus zeroconf functions.
1352 (defun tramp-zeroconf-parse-workstation-device-names (ignore)
1353 "Return a list of (user host) tuples allowed to access."
1356 (list nil
(zeroconf-service-host x
)))
1357 (zeroconf-list-services "_workstation._tcp")))
1359 (defun tramp-zeroconf-parse-webdav-device-names (ignore)
1360 "Return a list of (user host) tuples allowed to access."
1363 (let ((host (zeroconf-service-host x
))
1364 (port (zeroconf-service-port x
))
1365 (text (zeroconf-service-txt x
))
1368 (setq host
(format "%s%s%d" host tramp-prefix-port-regexp port
)))
1369 ;; A user is marked in a TXT field like "u=guest".
1371 (when (string-match "u=\\(.+\\)$" (car text
))
1372 (setq user
(match-string 1 (car text
))))
1373 (setq text
(cdr text
)))
1375 (zeroconf-list-services "_webdav._tcp")))
1377 ;; Add completion function for DAV and DAVS methods.
1378 (when (member zeroconf-service-avahi
(dbus-list-known-names :system
))
1379 (zeroconf-init tramp-gvfs-zeroconf-domain
)
1380 (tramp-set-completion-function
1381 "sftp" '((tramp-zeroconf-parse-workstation-device-names "")))
1382 (tramp-set-completion-function
1383 "dav" '((tramp-zeroconf-parse-webdav-device-names "")))
1384 (tramp-set-completion-function
1385 "davs" '((tramp-zeroconf-parse-webdav-device-names ""))))
1388 ;; D-Bus SYNCE functions.
1390 (defun tramp-synce-list-devices ()
1391 "Return all discovered synce devices as list.
1392 They are retrieved from the hal daemon."
1393 (let (tramp-synce-devices)
1395 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1396 :system tramp-hal-service tramp-hal-path-manager
1397 tramp-hal-interface-manager
"GetAllDevices"))
1398 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1399 :system tramp-hal-service device tramp-hal-interface-device
1400 "PropertyExists" "sync.plugin")
1402 'tramp-synce-devices
1403 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1404 :system tramp-hal-service device tramp-hal-interface-device
1405 "GetPropertyString" "pda.pocketpc.name"))))
1406 (tramp-message tramp-gvfs-dbus-event-vector
10 "%s" tramp-synce-devices
)
1407 tramp-synce-devices
))
1409 (defun tramp-synce-parse-device-names (ignore)
1410 "Return a list of (nil host) tuples allowed to access."
1412 (lambda (x) (list nil x
))
1413 (tramp-synce-list-devices)))
1415 ;; Add completion function for SYNCE method.
1416 (tramp-set-completion-function
1417 "synce" '((tramp-synce-parse-device-names "")))
1419 (add-hook 'tramp-unload-hook
1421 (unload-feature 'tramp-gvfs
'force
)))
1423 (provide 'tramp-gvfs
)
1427 ;; * Host name completion via smb-server or smb-network.
1428 ;; * Check, how two shares of the same SMB server can be mounted in
1430 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1432 ;; * Implement obex for other serial communication but bluetooth.
1434 ;;; tramp-gvfs.el ends here