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
107 ;; We call several `tramp-handle-*' functions directly. So we must
108 ;; reqire that package as well.
117 (defcustom tramp-gvfs-methods
'("dav" "davs" "obex" "synce")
118 "*List of methods for remote files, accessed with GVFS."
121 :type
'(repeat (choice (const "dav")
129 ;; Add a default for `tramp-default-user-alist'. Rule: For the SYNCE
130 ;; method, no user is chosen.
131 (add-to-list 'tramp-default-user-alist
134 (defcustom tramp-gvfs-zeroconf-domain
"local"
135 "*Zeroconf domain to be used for discovering services, like host names."
140 ;; Add the methods to `tramp-methods', in order to allow minibuffer
143 (when (featurep 'dbusbind
)
144 (dolist (elt tramp-gvfs-methods
)
145 (unless (assoc elt tramp-methods
)
146 (add-to-list 'tramp-methods
(cons elt nil
)))))
148 (defconst tramp-gvfs-path-tramp
(concat dbus-path-emacs
"/Tramp")
149 "The preceeding object path for own objects.")
151 (defconst tramp-gvfs-service-daemon
"org.gtk.vfs.Daemon"
152 "The well known name of the GVFS daemon.")
154 ;; Check that GVFS is available. D-Bus integration is available since
155 ;; Emacs 23 on some system types. We don't call `dbus-ping', because
156 ;; this would load dbus.el.
157 (unless (and (tramp-compat-funcall 'dbus-get-unique-name
:session
)
158 (tramp-compat-process-running-p "gvfs-fuse-daemon"))
159 (error "Package `tramp-gvfs' not supported"))
161 (defconst tramp-gvfs-path-mounttracker
"/org/gtk/vfs/mounttracker"
162 "The object path of the GVFS daemon.")
164 (defconst tramp-gvfs-interface-mounttracker
"org.gtk.vfs.MountTracker"
165 "The mount tracking interface in the GVFS daemon.")
167 ;; <interface name='org.gtk.vfs.MountTracker'>
168 ;; <method name='listMounts'>
169 ;; <arg name='mount_info_list'
170 ;; type='a{sosssssbay{aya{say}}ay}'
173 ;; <method name='mountLocation'>
174 ;; <arg name='mount_spec' type='{aya{say}}' direction='in'/>
175 ;; <arg name='dbus_id' type='s' direction='in'/>
176 ;; <arg name='object_path' type='o' direction='in'/>
178 ;; <signal name='mounted'>
179 ;; <arg name='mount_info'
180 ;; type='{sosssssbay{aya{say}}ay}'/>
182 ;; <signal name='unmounted'>
183 ;; <arg name='mount_info'
184 ;; type='{sosssssbay{aya{say}}ay}'/>
190 ;; OBJECT_PATH object_path
191 ;; STRING display_name
192 ;; STRING stable_name
193 ;; STRING x_content_types Since GVFS 1.0 only !!!
195 ;; STRING prefered_filename_encoding
196 ;; BOOLEAN user_visible
197 ;; ARRAY BYTE fuse_mountpoint
199 ;; ARRAY BYTE mount_prefix
201 ;; STRUCT mount_spec_item
202 ;; STRING key (server, share, type, user, host, port)
204 ;; ARRAY BYTE default_location Since GVFS 1.5 only !!!
206 (defconst tramp-gvfs-interface-mountoperation
"org.gtk.vfs.MountOperation"
207 "Used by the dbus-proxying implementation of GMountOperation.")
209 ;; <interface name='org.gtk.vfs.MountOperation'>
210 ;; <method name='askPassword'>
211 ;; <arg name='message' type='s' direction='in'/>
212 ;; <arg name='default_user' type='s' direction='in'/>
213 ;; <arg name='default_domain' type='s' direction='in'/>
214 ;; <arg name='flags' type='u' direction='in'/>
215 ;; <arg name='handled' type='b' direction='out'/>
216 ;; <arg name='aborted' type='b' direction='out'/>
217 ;; <arg name='password' type='s' direction='out'/>
218 ;; <arg name='username' type='s' direction='out'/>
219 ;; <arg name='domain' type='s' direction='out'/>
220 ;; <arg name='anonymous' type='b' direction='out'/>
221 ;; <arg name='password_save' type='u' direction='out'/>
223 ;; <method name='askQuestion'>
224 ;; <arg name='message' type='s' direction='in'/>
225 ;; <arg name='choices' type='as' direction='in'/>
226 ;; <arg name='handled' type='b' direction='out'/>
227 ;; <arg name='aborted' type='b' direction='out'/>
228 ;; <arg name='choice' type='u' direction='out'/>
232 ;; The following flags are used in "askPassword". They are defined in
233 ;; /usr/include/glib-2.0/gio/gioenums.h.
235 (defconst tramp-gvfs-password-need-password
1
236 "Operation requires a password.")
238 (defconst tramp-gvfs-password-need-username
2
239 "Operation requires a username.")
241 (defconst tramp-gvfs-password-need-domain
4
242 "Operation requires a domain.")
244 (defconst tramp-gvfs-password-saving-supported
8
245 "Operation supports saving settings.")
247 (defconst tramp-gvfs-password-anonymous-supported
16
248 "Operation supports anonymous users.")
250 (defconst tramp-bluez-service
"org.bluez"
251 "The well known name of the BLUEZ service.")
253 (defconst tramp-bluez-interface-manager
"org.bluez.Manager"
254 "The manager interface of the BLUEZ daemon.")
256 ;; <interface name='org.bluez.Manager'>
257 ;; <method name='DefaultAdapter'>
258 ;; <arg type='o' direction='out'/>
260 ;; <method name='FindAdapter'>
261 ;; <arg type='s' direction='in'/>
262 ;; <arg type='o' direction='out'/>
264 ;; <method name='ListAdapters'>
265 ;; <arg type='ao' direction='out'/>
267 ;; <signal name='AdapterAdded'>
270 ;; <signal name='AdapterRemoved'>
273 ;; <signal name='DefaultAdapterChanged'>
278 (defconst tramp-bluez-interface-adapter
"org.bluez.Adapter"
279 "The adapter interface of the BLUEZ daemon.")
281 ;; <interface name='org.bluez.Adapter'>
282 ;; <method name='GetProperties'>
283 ;; <arg type='a{sv}' direction='out'/>
285 ;; <method name='SetProperty'>
286 ;; <arg type='s' direction='in'/>
287 ;; <arg type='v' direction='in'/>
289 ;; <method name='RequestMode'>
290 ;; <arg type='s' direction='in'/>
292 ;; <method name='ReleaseMode'/>
293 ;; <method name='RequestSession'/>
294 ;; <method name='ReleaseSession'/>
295 ;; <method name='StartDiscovery'/>
296 ;; <method name='StopDiscovery'/>
297 ;; <method name='ListDevices'>
298 ;; <arg type='ao' direction='out'/>
300 ;; <method name='CreateDevice'>
301 ;; <arg type='s' direction='in'/>
302 ;; <arg type='o' direction='out'/>
304 ;; <method name='CreatePairedDevice'>
305 ;; <arg type='s' direction='in'/>
306 ;; <arg type='o' direction='in'/>
307 ;; <arg type='s' direction='in'/>
308 ;; <arg type='o' direction='out'/>
310 ;; <method name='CancelDeviceCreation'>
311 ;; <arg type='s' direction='in'/>
313 ;; <method name='RemoveDevice'>
314 ;; <arg type='o' direction='in'/>
316 ;; <method name='FindDevice'>
317 ;; <arg type='s' direction='in'/>
318 ;; <arg type='o' direction='out'/>
320 ;; <method name='RegisterAgent'>
321 ;; <arg type='o' direction='in'/>
322 ;; <arg type='s' direction='in'/>
324 ;; <method name='UnregisterAgent'>
325 ;; <arg type='o' direction='in'/>
327 ;; <signal name='DeviceCreated'>
330 ;; <signal name='DeviceRemoved'>
333 ;; <signal name='DeviceFound'>
335 ;; <arg type='a{sv}'/>
337 ;; <signal name='PropertyChanged'>
341 ;; <signal name='DeviceDisappeared'>
346 (defcustom tramp-bluez-discover-devices-timeout
60
347 "Defines seconds since last bluetooth device discovery before rescanning.
348 A value of 0 would require an immediate discovery during hostname
349 completion, nil means to use always cached values for discovered
353 :type
'(choice (const nil
) integer
))
355 (defvar tramp-bluez-discovery nil
356 "Indicator for a running bluetooth device discovery.
357 It keeps the timestamp of last discovery.")
359 (defvar tramp-bluez-devices nil
360 "Alist of detected bluetooth devices.
361 Every entry is a list (NAME ADDRESS).")
363 (defconst tramp-hal-service
"org.freedesktop.Hal"
364 "The well known name of the HAL service.")
366 (defconst tramp-hal-path-manager
"/org/freedesktop/Hal/Manager"
367 "The object path of the HAL daemon manager.")
369 (defconst tramp-hal-interface-manager
"org.freedesktop.Hal.Manager"
370 "The manager interface of the HAL daemon.")
372 (defconst tramp-hal-interface-device
"org.freedesktop.Hal.Device"
373 "The device interface of the HAL daemon.")
376 ;; New handlers should be added here.
377 (defconst tramp-gvfs-file-name-handler-alist
379 (access-file . ignore
)
380 (add-name-to-file . tramp-gvfs-handle-copy-file
)
381 ;; `byte-compiler-base-file-name' performed by default handler.
382 (copy-file . tramp-gvfs-handle-copy-file
)
383 (delete-directory . tramp-gvfs-handle-delete-directory
)
384 (delete-file . tramp-gvfs-handle-delete-file
)
385 ;; `diff-latest-backup-file' performed by default handler.
386 (directory-file-name . tramp-handle-directory-file-name
)
387 (directory-files . tramp-gvfs-handle-directory-files
)
388 (directory-files-and-attributes
389 . tramp-gvfs-handle-directory-files-and-attributes
)
390 (dired-call-process . ignore
)
391 (dired-compress-file . ignore
)
392 (dired-uncache . tramp-handle-dired-uncache
)
393 ;; `executable-find' is not official yet. performed by default handler.
394 (expand-file-name . tramp-gvfs-handle-expand-file-name
)
395 ;; `file-accessible-directory-p' performed by default handler.
396 (file-attributes . tramp-gvfs-handle-file-attributes
)
397 (file-directory-p . tramp-gvfs-handle-file-directory-p
)
398 (file-executable-p . tramp-gvfs-handle-file-executable-p
)
399 (file-exists-p . tramp-gvfs-handle-file-exists-p
)
400 (file-local-copy . tramp-gvfs-handle-file-local-copy
)
401 ;; `file-modes' performed by default handler.
402 (file-name-all-completions . tramp-gvfs-handle-file-name-all-completions
)
403 (file-name-as-directory . tramp-handle-file-name-as-directory
)
404 (file-name-completion . tramp-handle-file-name-completion
)
405 (file-name-directory . tramp-handle-file-name-directory
)
406 (file-name-nondirectory . tramp-handle-file-name-nondirectory
)
407 ;; `file-name-sans-versions' performed by default handler.
408 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p
)
409 (file-ownership-preserved-p . ignore
)
410 (file-readable-p . tramp-gvfs-handle-file-readable-p
)
411 (file-regular-p . tramp-handle-file-regular-p
)
412 (file-remote-p . tramp-handle-file-remote-p
)
413 (file-selinux-context . tramp-gvfs-handle-file-selinux-context
)
414 (file-symlink-p . tramp-handle-file-symlink-p
)
415 ;; `file-truename' performed by default handler.
416 (file-writable-p . tramp-gvfs-handle-file-writable-p
)
417 (find-backup-file-name . tramp-handle-find-backup-file-name
)
418 ;; `find-file-noselect' performed by default handler.
419 ;; `get-file-buffer' performed by default handler.
420 (insert-directory . tramp-gvfs-handle-insert-directory
)
421 (insert-file-contents . tramp-gvfs-handle-insert-file-contents
)
422 (load . tramp-handle-load
)
423 (make-directory . tramp-gvfs-handle-make-directory
)
424 (make-directory-internal . ignore
)
425 (make-symbolic-link . ignore
)
426 (process-file . tramp-gvfs-handle-process-file
)
427 (rename-file . tramp-gvfs-handle-rename-file
)
428 (set-file-modes . tramp-gvfs-handle-set-file-modes
)
429 (set-file-selinux-context . tramp-gvfs-handle-set-file-selinux-context
)
430 (set-visited-file-modtime . tramp-gvfs-handle-set-visited-file-modtime
)
431 (shell-command . tramp-gvfs-handle-shell-command
)
432 (start-file-process . tramp-gvfs-handle-start-file-process
)
433 (substitute-in-file-name . tramp-handle-substitute-in-file-name
)
434 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory
)
435 (vc-registered . ignore
)
436 (verify-visited-file-modtime
437 . tramp-gvfs-handle-verify-visited-file-modtime
)
438 (write-region . tramp-gvfs-handle-write-region
)
440 "Alist of handler functions for Tramp GVFS method.
441 Operations not mentioned here will be handled by the default Emacs primitives.")
444 (defsubst tramp-gvfs-file-name-p
(filename)
445 "Check if it's a filename handled by the GVFS daemon."
446 (and (tramp-tramp-file-p filename
)
448 (tramp-file-name-method (tramp-dissect-file-name filename
))))
449 (and (stringp method
) (member method tramp-gvfs-methods
)))))
452 (defun tramp-gvfs-file-name-handler (operation &rest args
)
453 "Invoke the GVFS related OPERATION.
454 First arg specifies the OPERATION, second arg is a list of arguments to
455 pass to the OPERATION."
456 (let ((fn (assoc operation tramp-gvfs-file-name-handler-alist
)))
458 (save-match-data (apply (cdr fn
) args
))
459 (tramp-run-real-handler operation args
))))
461 ;; This might be moved to tramp.el. It shall be the first file name
464 (when (featurep 'dbusbind
)
465 (add-to-list 'tramp-foreign-file-name-handler-alist
466 (cons 'tramp-gvfs-file-name-p
'tramp-gvfs-file-name-handler
)))
468 (defun tramp-gvfs-stringify-dbus-message (message)
469 "Convert a D-Bus message into readable UTF8 strings, used for traces."
471 ((and (consp message
) (characterp (car message
)))
472 (format "%S" (dbus-byte-array-to-string message
)))
474 (mapcar 'tramp-gvfs-stringify-dbus-message message
))
476 (format "%S" message
))
479 (defmacro with-tramp-dbus-call-method
480 (vec synchronous bus service path interface method
&rest args
)
481 "Apply a D-Bus call on bus BUS.
483 If SYNCHRONOUS is non-nil, the call is synchronously. Otherwise,
484 it is an asynchronous call, with `ignore' as callback function.
486 The other arguments have the same meaning as with `dbus-call-method'
487 or `dbus-call-method-asynchronously'. Additionally, the call
488 will be traced by Tramp with trace level 6."
489 `(let ((func (if ,synchronous
490 'dbus-call-method
'dbus-call-method-asynchronously
))
491 (args (append (list ,bus
,service
,path
,interface
,method
)
492 (if ,synchronous
(list ,@args
) (list 'ignore
,@args
))))
494 (tramp-message ,vec
6 "%s %s" func args
)
495 (setq result
(apply func args
))
496 (tramp-message ,vec
6 "%s" (tramp-gvfs-stringify-dbus-message result
))
499 (put 'with-tramp-dbus-call-method
'lisp-indent-function
2)
500 (put 'with-tramp-dbus-call-method
'edebug-form-spec
'(form symbolp body
))
501 (font-lock-add-keywords 'emacs-lisp-mode
'("\\<with-tramp-dbus-call-method\\>"))
503 (defmacro with-tramp-gvfs-error-message
(filename handler
&rest args
)
504 "Apply a Tramp GVFS `handler'.
505 In case of an error, modify the error message by replacing
506 `filename' with its GVFS mounted name."
507 `(let ((fuse-file-name (regexp-quote (tramp-gvfs-fuse-file-name ,filename
)))
510 (tramp-compat-funcall ,handler
,@args
)
514 (when (and (stringp (car elt
))
515 (string-match fuse-file-name
(car elt
)))
516 (setcar elt
(replace-match ,filename t t
(car elt
))))
517 (setq elt
(cdr elt
)))
518 (signal (car err
) (cdr err
))))))
520 (put 'with-tramp-gvfs-error-message
'lisp-indent-function
2)
521 (put 'with-tramp-gvfs-error-message
'edebug-form-spec
'(form symbolp body
))
522 (font-lock-add-keywords 'emacs-lisp-mode
'("\\<with-tramp-gvfs-error-message\\>"))
524 (defvar tramp-gvfs-dbus-event-vector nil
525 "Current Tramp file name to be used, as vector.
526 It is needed when D-Bus signals or errors arrive, because there
527 is no information where to trace the message.")
529 (defun tramp-gvfs-dbus-event-error (event err
)
530 "Called when a D-Bus error message arrives, see `dbus-event-error-hooks'."
531 (when tramp-gvfs-dbus-event-vector
532 ;(tramp-cleanup-connection tramp-gvfs-dbus-event-vector)
533 (tramp-message tramp-gvfs-dbus-event-vector
10 "%S" event
)
534 (tramp-error tramp-gvfs-dbus-event-vector
'file-error
"%s" (cadr err
))))
536 (add-hook 'dbus-event-error-hooks
'tramp-gvfs-dbus-event-error
)
539 ;; File name primitives.
541 (defun tramp-gvfs-handle-copy-file
542 (filename newname
&optional ok-if-already-exists keep-date
543 preserve-uid-gid preserve-selinux-context
)
544 "Like `copy-file' for Tramp files."
545 (with-parsed-tramp-file-name
546 (if (tramp-tramp-file-p filename
) filename newname
) nil
547 (with-progress-reporter
548 v
0 (format "Copying %s to %s" filename newname
)
552 (if (tramp-gvfs-file-name-p filename
)
553 (tramp-gvfs-fuse-file-name filename
)
555 (if (tramp-gvfs-file-name-p newname
)
556 (tramp-gvfs-fuse-file-name newname
)
558 ok-if-already-exists keep-date preserve-uid-gid
)))
559 (when preserve-selinux-context
560 (setq args
(append args
(list preserve-selinux-context
))))
561 (apply 'copy-file args
))
563 ;; Error case. Let's try it with the GVFS utilities.
565 (tramp-message v
4 "`copy-file' failed, trying `gvfs-copy'")
569 (append (if (or keep-date preserve-uid-gid
)
573 (tramp-gvfs-url-file-name filename
)
574 (tramp-gvfs-url-file-name newname
)))))
575 (apply 'tramp-gvfs-send-command v
"gvfs-copy" args
)))
576 ;; Propagate the error.
577 (tramp-error v
(car err
) "%s" (cdr err
)))))))
579 (when (file-remote-p newname
)
580 (with-parsed-tramp-file-name newname nil
581 (tramp-flush-file-property v
(file-name-directory localname
))
582 (tramp-flush-file-property v localname
))))
584 (defun tramp-gvfs-handle-delete-directory (directory &optional recursive
)
585 "Like `delete-directory' for Tramp files."
586 (tramp-compat-delete-directory
587 (tramp-gvfs-fuse-file-name directory
) recursive
))
589 (defun tramp-gvfs-handle-delete-file (filename &optional trash
)
590 "Like `delete-file' for Tramp files."
591 (tramp-compat-delete-file (tramp-gvfs-fuse-file-name filename
) trash
))
593 (defun tramp-gvfs-handle-directory-files
594 (directory &optional full match nosort
)
595 "Like `directory-files' for Tramp files."
596 (let ((fuse-file-name (tramp-gvfs-fuse-file-name directory
)))
599 (if (string-match fuse-file-name x
)
600 (replace-match directory t t x
)
602 (directory-files fuse-file-name full match nosort
))))
604 (defun tramp-gvfs-handle-directory-files-and-attributes
605 (directory &optional full match nosort id-format
)
606 "Like `directory-files-and-attributes' for Tramp files."
607 (let ((fuse-file-name (tramp-gvfs-fuse-file-name directory
)))
610 (when (string-match fuse-file-name
(car x
))
611 (setcar x
(replace-match directory t t
(car x
))))
613 (directory-files-and-attributes
614 fuse-file-name full match nosort id-format
))))
616 (defun tramp-gvfs-handle-expand-file-name (name &optional dir
)
617 "Like `expand-file-name' for Tramp files."
618 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
619 (setq dir
(or dir default-directory
"/"))
620 ;; Unless NAME is absolute, concat DIR and NAME.
621 (unless (file-name-absolute-p name
)
622 (setq name
(concat (file-name-as-directory dir
) name
)))
623 ;; If NAME is not a Tramp file, run the real handler.
624 (if (not (tramp-tramp-file-p name
))
625 (tramp-run-real-handler 'expand-file-name
(list name nil
))
627 (with-parsed-tramp-file-name name nil
628 ;; If there is a default location, expand tilde.
629 (when (string-match "\\`\\(~\\)\\(/\\|\\'\\)" localname
)
631 (tramp-gvfs-maybe-open-connection (vector method user host
"/")))
634 (tramp-get-file-property v
"/" "default-location" "~")
636 ;; Tilde expansion is not possible.
637 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname
)
640 "Cannot expand tilde in file `%s'" name
))
641 (unless (tramp-run-real-handler 'file-name-absolute-p
(list localname
))
642 (setq localname
(concat "/" localname
)))
643 ;; We do not pass "/..".
644 (if (string-equal "smb" method
)
645 (when (string-match "^/[^/]+\\(/\\.\\./?\\)" localname
)
646 (setq localname
(replace-match "/" t t localname
1)))
647 (when (string-match "^/\\.\\./?" localname
)
648 (setq localname
(replace-match "/" t t localname
))))
649 ;; There might be a double slash. Remove this.
650 (while (string-match "//" localname
)
651 (setq localname
(replace-match "/" t t localname
)))
652 ;; No tilde characters in file name, do normal
653 ;; `expand-file-name' (this does "/./" and "/../").
654 (tramp-make-tramp-file-name
656 (tramp-run-real-handler
657 'expand-file-name
(list localname
))))))
659 (defun tramp-gvfs-handle-file-attributes (filename &optional id-format
)
660 "Like `file-attributes' for Tramp files."
661 (file-attributes (tramp-gvfs-fuse-file-name filename
) id-format
))
663 (defun tramp-gvfs-handle-file-directory-p (filename)
664 "Like `file-directory-p' for Tramp files."
665 (file-directory-p (tramp-gvfs-fuse-file-name filename
)))
667 (defun tramp-gvfs-handle-file-executable-p (filename)
668 "Like `file-executable-p' for Tramp files."
669 (file-executable-p (tramp-gvfs-fuse-file-name filename
)))
671 (defun tramp-gvfs-handle-file-exists-p (filename)
672 "Like `file-exists-p' for Tramp files."
673 (file-exists-p (tramp-gvfs-fuse-file-name filename
)))
675 (defun tramp-gvfs-handle-file-local-copy (filename)
676 "Like `file-local-copy' for Tramp files."
677 (with-parsed-tramp-file-name filename nil
678 (let ((tmpfile (tramp-compat-make-temp-file filename
)))
679 (unless (file-exists-p filename
)
682 "Cannot make local copy of non-existing file `%s'" filename
))
683 (copy-file filename tmpfile t t
)
686 (defun tramp-gvfs-handle-file-name-all-completions (filename directory
)
687 "Like `file-name-all-completions' for Tramp files."
688 (unless (save-match-data (string-match "/" filename
))
689 (file-name-all-completions filename
(tramp-gvfs-fuse-file-name directory
))))
691 (defun tramp-gvfs-handle-file-readable-p (filename)
692 "Like `file-readable-p' for Tramp files."
693 (file-readable-p (tramp-gvfs-fuse-file-name filename
)))
695 (defun tramp-gvfs-handle-file-selinux-context (filename)
696 "Like `file-selinux-context' for Tramp files."
697 (tramp-compat-funcall
698 'file-selinux-context
(tramp-gvfs-fuse-file-name filename
)))
700 (defun tramp-gvfs-handle-file-writable-p (filename)
701 "Like `file-writable-p' for Tramp files."
702 (file-writable-p (tramp-gvfs-fuse-file-name filename
)))
704 (defun tramp-gvfs-handle-insert-directory
705 (filename switches
&optional wildcard full-directory-p
)
706 "Like `insert-directory' for Tramp files."
708 (tramp-gvfs-fuse-file-name filename
) switches wildcard full-directory-p
))
710 (defun tramp-gvfs-handle-insert-file-contents
711 (filename &optional visit beg end replace
)
712 "Like `insert-file-contents' for Tramp files."
714 (let ((fuse-file-name (tramp-gvfs-fuse-file-name filename
))
716 (insert-file-contents
717 (tramp-gvfs-fuse-file-name filename
) visit beg end replace
)))
718 (when (string-match fuse-file-name
(car result
))
719 (setcar result
(replace-match filename t t
(car result
))))
721 (setq buffer-file-name filename
)))
723 (defun tramp-gvfs-handle-make-directory (dir &optional parents
)
724 "Like `make-directory' for Tramp files."
725 (with-parsed-tramp-file-name dir nil
727 (with-tramp-gvfs-error-message dir
'make-directory
728 (tramp-gvfs-fuse-file-name dir
) parents
)
730 ;; Error case. Let's try it with the GVFS utilities.
732 (tramp-message v
4 "`make-directory' failed, trying `gvfs-mkdir'")
735 (tramp-gvfs-send-command
736 v
"gvfs-mkdir" (tramp-gvfs-url-file-name dir
)))
737 ;; Propagate the error.
738 (tramp-error v
(car err
) "%s" (cdr err
)))))))
740 (defun tramp-gvfs-handle-process-file
741 (program &optional infile destination display
&rest args
)
742 "Like `process-file' for Tramp files."
743 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory
)))
744 (apply 'call-process program infile destination display args
)))
746 (defun tramp-gvfs-handle-rename-file
747 (filename newname
&optional ok-if-already-exists
)
748 "Like `rename-file' for Tramp files."
749 (with-parsed-tramp-file-name
750 (if (tramp-tramp-file-p filename
) filename newname
) nil
751 (with-progress-reporter
752 v
0 (format "Renaming %s to %s" filename newname
)
755 (if (tramp-gvfs-file-name-p filename
)
756 (tramp-gvfs-fuse-file-name filename
)
758 (if (tramp-gvfs-file-name-p newname
)
759 (tramp-gvfs-fuse-file-name newname
)
761 ok-if-already-exists
)
763 ;; Error case. Let's try it with the GVFS utilities.
765 (tramp-message v
4 "`rename-file' failed, trying `gvfs-move'")
768 (tramp-gvfs-send-command
770 (tramp-gvfs-url-file-name filename
)
771 (tramp-gvfs-url-file-name newname
)))
772 ;; Propagate the error.
773 (tramp-error v
(car err
) "%s" (cdr err
)))))))
775 (when (file-remote-p filename
)
776 (with-parsed-tramp-file-name filename nil
777 (tramp-flush-file-property v
(file-name-directory localname
))
778 (tramp-flush-file-property v localname
)))
780 (when (file-remote-p newname
)
781 (with-parsed-tramp-file-name newname nil
782 (tramp-flush-file-property v
(file-name-directory localname
))
783 (tramp-flush-file-property v localname
))))
785 (defun tramp-gvfs-handle-set-file-modes (filename mode
)
786 "Like `set-file-modes' for Tramp files."
787 (with-tramp-gvfs-error-message filename
'set-file-modes
788 (tramp-gvfs-fuse-file-name filename
) mode
))
790 (defun tramp-gvfs-handle-set-file-selinux-context (filename context
)
791 "Like `set-file-selinux-context' for Tramp files."
792 (with-tramp-gvfs-error-message filename
'set-file-selinux-context
793 (tramp-gvfs-fuse-file-name filename
) context
))
795 (defun tramp-gvfs-handle-set-visited-file-modtime (&optional time-list
)
796 "Like `set-visited-file-modtime' for Tramp files."
797 (let ((buffer-file-name (tramp-gvfs-fuse-file-name (buffer-file-name))))
798 (set-visited-file-modtime time-list
)))
800 (defun tramp-gvfs-handle-shell-command
801 (command &optional output-buffer error-buffer
)
802 "Like `shell-command' for Tramp files."
803 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory
)))
804 (shell-command command output-buffer error-buffer
)))
806 (defun tramp-gvfs-handle-start-file-process (name buffer program
&rest args
)
807 "Like `start-file-process' for Tramp files."
808 (let ((default-directory (tramp-gvfs-fuse-file-name default-directory
)))
809 (apply 'start-process name buffer program args
)))
811 (defun tramp-gvfs-handle-verify-visited-file-modtime (buf)
812 "Like `verify-visited-file-modtime' for Tramp files."
813 (with-current-buffer buf
814 (let ((buffer-file-name (tramp-gvfs-fuse-file-name (buffer-file-name))))
815 (verify-visited-file-modtime buf
))))
817 (defun tramp-gvfs-handle-write-region
818 (start end filename
&optional append visit lockname confirm
)
819 "Like `write-region' for Tramp files."
820 (with-parsed-tramp-file-name filename nil
822 (with-tramp-gvfs-error-message filename
'write-region
823 start end
(tramp-gvfs-fuse-file-name filename
)
824 append visit lockname confirm
)
826 ;; Error case. Let's try rename.
828 (let ((tmpfile (tramp-compat-make-temp-file filename
)))
829 (tramp-message v
4 "`write-region' failed, trying `rename-file'")
830 (write-region start end tmpfile
)
832 (rename-file tmpfile filename
)
834 (delete-file tmpfile
)
835 (tramp-error v
(car err
) "%s" (cdr err
)))))))
837 ;; Set file modification time.
838 (when (or (eq visit t
) (stringp visit
))
839 (set-visited-file-modtime (nth 5 (file-attributes filename
))))
842 (when (or (eq visit t
) (null visit
) (stringp visit
))
843 (tramp-message v
0 "Wrote %s" filename
))
844 (run-hooks 'tramp-handle-write-region-hook
)))
847 ;; File name conversions.
849 (defun tramp-gvfs-url-file-name (filename)
850 "Return FILENAME in URL syntax."
851 ;; "/" must NOT be hexlified.
852 (let ((url-unreserved-chars (append '(?
/) url-unreserved-chars
)))
854 (if (tramp-tramp-file-p filename
)
855 (with-parsed-tramp-file-name (file-truename filename
) nil
856 (when (string-match tramp-user-with-domain-regexp user
)
858 (concat (match-string 2 user
) ";" (match-string 2 user
))))
859 (url-parse-make-urlobj
861 (tramp-file-name-real-host v
) (tramp-file-name-port v
)
862 (url-hexify-string localname
)))
863 (url-parse-make-urlobj
864 "file" nil nil nil nil
(url-hexify-string (file-truename filename
)))))))
866 (defun tramp-gvfs-object-path (filename)
867 "Create a D-Bus object path from FILENAME."
868 (expand-file-name (dbus-escape-as-identifier filename
) tramp-gvfs-path-tramp
))
870 (defun tramp-gvfs-file-name (object-path)
871 "Retrieve file name from D-Bus OBJECT-PATH."
872 (dbus-unescape-from-identifier
873 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path
)))
875 (defun tramp-gvfs-fuse-file-name (filename)
876 "Return FUSE file name, which is directly accessible."
877 (with-parsed-tramp-file-name (expand-file-name filename
) nil
878 (tramp-gvfs-maybe-open-connection v
)
879 (let ((prefix (tramp-get-file-property v
"/" "prefix" ""))
881 (tramp-get-file-property v
"/" "fuse-mountpoint" nil
)))
882 (unless fuse-mountpoint
884 v
'file-error
"There is no FUSE mount point for `%s'" filename
))
885 ;; We must hide the prefix, if any.
886 (when (string-match (concat "^" (regexp-quote prefix
)) localname
)
887 (setq localname
(replace-match "" t t localname
)))
889 v
10 "remote file `%s' is local file `%s'"
890 filename
(concat fuse-mountpoint localname
))
891 (concat fuse-mountpoint localname
))))
893 (defun tramp-bluez-address (device)
894 "Return bluetooth device address from a given bluetooth DEVICE name."
895 (when (stringp device
)
896 (if (string-match tramp-ipv6-regexp device
)
897 (match-string 0 device
)
898 (cadr (assoc device
(tramp-bluez-list-devices))))))
900 (defun tramp-bluez-device (address)
901 "Return bluetooth device name from a given bluetooth device ADDRESS.
902 ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
903 (when (stringp address
)
904 (while (string-match "[][]" address
)
905 (setq address
(replace-match "" t t address
)))
907 (dolist (item (tramp-bluez-list-devices) result
)
908 (when (string-match address
(cadr item
))
909 (setq result
(car item
)))))))
912 ;; D-Bus GVFS functions.
914 (defun tramp-gvfs-handler-askpassword (message user domain flags
)
915 "Implementation for the \"org.gtk.vfs.MountOperation.askPassword\" method."
917 (tramp-gvfs-file-name (dbus-event-path-name last-input-event
)))
921 (if (string-match "\\([pP]assword\\|[pP]assphrase\\)" message
)
922 (capitalize (match-string 1 message
))
928 (with-parsed-tramp-file-name filename l
929 (when (and (zerop (length user
))
931 (zerop (logand flags tramp-gvfs-password-need-username
))))
932 (setq user
(read-string "User name: ")))
933 (when (and (zerop (length domain
))
934 (not (zerop (logand flags tramp-gvfs-password-need-domain
))))
935 (setq domain
(read-string "Domain name: ")))
937 (tramp-message l
6 "%S %S %S %d" message user domain flags
)
938 (setq tramp-current-method l-method
939 tramp-current-user user
940 tramp-current-host l-host
941 password
(tramp-read-passwd
942 (tramp-get-connection-process l
) pw-prompt
))
945 (if (stringp password
)
947 t
;; password handled.
948 nil
;; no abort of D-Bus.
950 (tramp-file-name-real-user l
)
952 nil
;; not anonymous.
953 0) ;; no password save.
954 ;; No password provided.
955 (list nil t
"" (tramp-file-name-real-user l
) domain nil
0)))
957 ;; When QUIT is raised, we shall return this information to D-Bus.
958 (quit (list nil t
"" "" "" nil
0)))))
960 (defun tramp-gvfs-handler-askquestion (message choices
)
961 "Implementation for the \"org.gtk.vfs.MountOperation.askQuestion\" method."
962 (save-window-excursion
963 (let ((enable-recursive-minibuffers t
)
967 (with-parsed-tramp-file-name
968 (tramp-gvfs-file-name (dbus-event-path-name last-input-event
)) nil
969 (tramp-message v
6 "%S %S" message choices
)
971 ;; In theory, there can be several choices. Until now,
972 ;; there is only the question whether to accept an unknown
975 ;; Preserve message for `progress-reporter'.
976 (with-temp-message ""
978 (pop-to-buffer (current-buffer))
979 (setq choice
(if (yes-or-no-p (concat (car choices
) " ")) 0 1))
980 (tramp-message v
6 "%d" choice
)))
982 ;; When the choice is "no", we set a dummy fuse-mountpoint
983 ;; in order to leave the timeout.
984 (unless (zerop choice
)
985 (tramp-set-file-property v
"/" "fuse-mountpoint" "/"))
989 nil
;; no abort of D-Bus.
992 ;; When QUIT is raised, we shall return this information to D-Bus.
993 (quit (list nil t
0))))))
995 (defun tramp-gvfs-handler-mounted-unmounted (mount-info)
996 "Signal handler for the \"org.gtk.vfs.MountTracker.mounted\" and
997 \"org.gtk.vfs.MountTracker.unmounted\" signals."
999 (let ((signal-name (dbus-event-member-name last-input-event
))
1001 ;; Jump over the first elements of the mount info. Since there
1002 ;; were changes in the antries, we cannot access dedicated
1004 (while (stringp (car elt
)) (setq elt
(cdr elt
)))
1005 (let* ((fuse-mountpoint (dbus-byte-array-to-string (cadr elt
)))
1006 (mount-spec (caddr elt
))
1007 (default-location (dbus-byte-array-to-string (cadddr elt
)))
1008 (method (dbus-byte-array-to-string
1009 (cadr (assoc "type" (cadr mount-spec
)))))
1010 (user (dbus-byte-array-to-string
1011 (cadr (assoc "user" (cadr mount-spec
)))))
1012 (domain (dbus-byte-array-to-string
1013 (cadr (assoc "domain" (cadr mount-spec
)))))
1014 (host (dbus-byte-array-to-string
1015 (cadr (or (assoc "host" (cadr mount-spec
))
1016 (assoc "server" (cadr mount-spec
))))))
1017 (port (dbus-byte-array-to-string
1018 (cadr (assoc "port" (cadr mount-spec
)))))
1019 (ssl (dbus-byte-array-to-string
1020 (cadr (assoc "ssl" (cadr mount-spec
)))))
1021 (prefix (concat (dbus-byte-array-to-string (car mount-spec
))
1022 (dbus-byte-array-to-string
1023 (cadr (assoc "share" (cadr mount-spec
)))))))
1024 (when (string-match "^smb" method
)
1025 (setq method
"smb"))
1026 (when (string-equal "obex" method
)
1027 (setq host
(tramp-bluez-device host
)))
1028 (when (and (string-equal "dav" method
) (string-equal "true" ssl
))
1029 (setq method
"davs"))
1030 (unless (zerop (length domain
))
1031 (setq user
(concat user tramp-prefix-domain-format domain
)))
1032 (unless (zerop (length port
))
1033 (setq host
(concat host tramp-prefix-port-format port
)))
1034 (with-parsed-tramp-file-name
1035 (tramp-make-tramp-file-name method user host
"") nil
1038 signal-name
(tramp-gvfs-stringify-dbus-message mount-info
))
1039 (tramp-set-file-property v
"/" "list-mounts" 'undef
)
1040 (if (string-equal signal-name
"unmounted")
1041 (tramp-set-file-property v
"/" "fuse-mountpoint" nil
)
1042 ;; Set prefix, mountpoint and location.
1043 (unless (string-equal prefix
"/")
1044 (tramp-set-file-property v
"/" "prefix" prefix
))
1045 (tramp-set-file-property v
"/" "fuse-mountpoint" fuse-mountpoint
)
1046 (tramp-set-file-property
1047 v
"/" "default-location" default-location
)))))))
1049 (dbus-register-signal
1050 :session nil tramp-gvfs-path-mounttracker
1051 tramp-gvfs-interface-mounttracker
"mounted"
1052 'tramp-gvfs-handler-mounted-unmounted
)
1054 (dbus-register-signal
1055 :session nil tramp-gvfs-path-mounttracker
1056 tramp-gvfs-interface-mounttracker
"unmounted"
1057 'tramp-gvfs-handler-mounted-unmounted
)
1059 (defun tramp-gvfs-connection-mounted-p (vec)
1060 "Check, whether the location is already mounted."
1062 (tramp-get-file-property vec
"/" "fuse-mountpoint" nil
)
1066 (with-file-property vec
"/" "list-mounts"
1067 (with-tramp-dbus-call-method vec t
1068 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1069 tramp-gvfs-interface-mounttracker
"listMounts"))
1071 ;; Jump over the first elements of the mount info. Since there
1072 ;; were changes in the antries, we cannot access dedicated
1074 (while (stringp (car elt
)) (setq elt
(cdr elt
)))
1075 (let* ((fuse-mountpoint (dbus-byte-array-to-string (cadr elt
)))
1076 (mount-spec (caddr elt
))
1077 (default-location (dbus-byte-array-to-string (cadddr elt
)))
1078 (method (dbus-byte-array-to-string
1079 (cadr (assoc "type" (cadr mount-spec
)))))
1080 (user (dbus-byte-array-to-string
1081 (cadr (assoc "user" (cadr mount-spec
)))))
1082 (domain (dbus-byte-array-to-string
1083 (cadr (assoc "domain" (cadr mount-spec
)))))
1084 (host (dbus-byte-array-to-string
1085 (cadr (or (assoc "host" (cadr mount-spec
))
1086 (assoc "server" (cadr mount-spec
))))))
1087 (port (dbus-byte-array-to-string
1088 (cadr (assoc "port" (cadr mount-spec
)))))
1089 (ssl (dbus-byte-array-to-string
1090 (cadr (assoc "ssl" (cadr mount-spec
)))))
1091 (prefix (concat (dbus-byte-array-to-string (car mount-spec
))
1092 (dbus-byte-array-to-string
1093 (cadr (assoc "share" (cadr mount-spec
)))))))
1094 (when (string-match "^smb" method
)
1095 (setq method
"smb"))
1096 (when (string-equal "obex" method
)
1097 (setq host
(tramp-bluez-device host
)))
1098 (when (and (string-equal "dav" method
) (string-equal "true" ssl
))
1099 (setq method
"davs"))
1100 (when (and (string-equal "synce" method
) (zerop (length user
)))
1101 (setq user
(or (tramp-file-name-user vec
) "")))
1102 (unless (zerop (length domain
))
1103 (setq user
(concat user tramp-prefix-domain-format domain
)))
1104 (unless (zerop (length port
))
1105 (setq host
(concat host tramp-prefix-port-format port
)))
1107 (string-equal method
(tramp-file-name-method vec
))
1108 (string-equal user
(or (tramp-file-name-user vec
) ""))
1109 (string-equal host
(tramp-file-name-host vec
))
1110 (string-match (concat "^" (regexp-quote prefix
))
1111 (tramp-file-name-localname vec
)))
1112 ;; Set prefix, mountpoint and location.
1113 (unless (string-equal prefix
"/")
1114 (tramp-set-file-property vec
"/" "prefix" prefix
))
1115 (tramp-set-file-property vec
"/" "fuse-mountpoint" fuse-mountpoint
)
1116 (tramp-set-file-property vec
"/" "default-location" default-location
)
1117 (throw 'mounted t
)))))))
1119 (defun tramp-gvfs-mount-spec (vec)
1120 "Return a mount-spec for \"org.gtk.vfs.MountTracker.mountLocation\"."
1121 (let* ((method (tramp-file-name-method vec
))
1122 (user (tramp-file-name-real-user vec
))
1123 (domain (tramp-file-name-domain vec
))
1124 (host (tramp-file-name-real-host vec
))
1125 (port (tramp-file-name-port vec
))
1126 (localname (tramp-file-name-localname vec
))
1127 (ssl (if (string-match "^davs" method
) "true" "false"))
1128 (mount-spec '(:array
))
1136 ((string-equal "smb" method
)
1137 (string-match "^/?\\([^/]+\\)" localname
)
1138 `((:struct
"type" ,(dbus-string-to-byte-array "smb-share"))
1139 (:struct
"server" ,(dbus-string-to-byte-array host
))
1140 (:struct
"share" ,(dbus-string-to-byte-array
1141 (match-string 1 localname
)))))
1142 ((string-equal "obex" method
)
1143 `((:struct
"type" ,(dbus-string-to-byte-array method
))
1144 (:struct
"host" ,(dbus-string-to-byte-array
1145 (concat "[" (tramp-bluez-address host
) "]")))))
1146 ((string-match "^dav" method
)
1147 `((:struct
"type" ,(dbus-string-to-byte-array "dav"))
1148 (:struct
"host" ,(dbus-string-to-byte-array host
))
1149 (:struct
"ssl" ,(dbus-string-to-byte-array ssl
))))
1151 `((:struct
"type" ,(dbus-string-to-byte-array method
))
1152 (:struct
"host" ,(dbus-string-to-byte-array host
)))))))
1157 `(:struct
"user" ,(dbus-string-to-byte-array user
))
1163 `(:struct
"domain" ,(dbus-string-to-byte-array domain
))
1169 `(:struct
"port" ,(dbus-string-to-byte-array (number-to-string port
)))
1172 (when (and (string-match "^dav" method
)
1173 (string-match "^/?[^/]+" localname
))
1174 (setq mount-pref
(match-string 0 localname
)))
1177 `(:struct
,(dbus-string-to-byte-array mount-pref
) ,mount-spec
)))
1180 ;; Connection functions
1182 (defun tramp-gvfs-maybe-open-connection (vec)
1183 "Maybe open a connection VEC.
1184 Does not do anything if a connection is already open, but re-opens the
1185 connection if a previous connection has died for some reason."
1187 ;; We set the file name, in case there are incoming D-Bus signals or
1189 (setq tramp-gvfs-dbus-event-vector vec
)
1191 ;; For password handling, we need a process bound to the connection
1192 ;; buffer. Therefore, we create a dummy process. Maybe there is a
1194 (unless (get-buffer-process (tramp-get-buffer vec
))
1195 (let ((p (make-network-process
1196 :name
(tramp-buffer-name vec
)
1197 :buffer
(tramp-get-buffer vec
)
1198 :server t
:host
'local
:service t
)))
1199 (tramp-set-process-query-on-exit-flag p nil
)))
1201 (unless (tramp-gvfs-connection-mounted-p vec
)
1202 (let* ((method (tramp-file-name-method vec
))
1203 (user (tramp-file-name-user vec
))
1204 (host (tramp-file-name-host vec
))
1206 (tramp-gvfs-object-path
1207 (tramp-make-tramp-file-name method user host
""))))
1209 (with-progress-reporter
1211 (if (zerop (length user
))
1212 (format "Opening connection for %s using %s" host method
)
1213 (format "Opening connection for %s@%s using %s" user host method
))
1215 ;; Enable auth-sorce and password-cache.
1216 (tramp-set-connection-property vec
"first-password-request" t
)
1218 ;; There will be a callback of "askPassword", when a password is
1220 (dbus-register-method
1221 :session dbus-service-emacs object-path
1222 tramp-gvfs-interface-mountoperation
"askPassword"
1223 'tramp-gvfs-handler-askpassword
)
1225 ;; There could be a callback of "askQuestion", when adding fingerprint.
1226 (dbus-register-method
1227 :session dbus-service-emacs object-path
1228 tramp-gvfs-interface-mountoperation
"askQuestion"
1229 'tramp-gvfs-handler-askquestion
)
1231 ;; The call must be asynchronously, because of the "askPassword"
1232 ;; or "askQuestion"callbacks.
1233 (with-tramp-dbus-call-method vec nil
1234 :session tramp-gvfs-service-daemon tramp-gvfs-path-mounttracker
1235 tramp-gvfs-interface-mounttracker
"mountLocation"
1236 (tramp-gvfs-mount-spec vec
) (dbus-get-unique-name :session
)
1237 :object-path object-path
)
1239 ;; We must wait, until the mount is applied. This will be
1240 ;; indicated by the "mounted" signal, i.e. the "fuse-mountpoint"
1244 (if (zerop (length (tramp-file-name-user vec
)))
1247 "Timeout reached mounting %s using %s" host method
)
1250 "Timeout reached mounting %s@%s using %s" user host method
)))
1251 (while (not (tramp-get-file-property vec
"/" "fuse-mountpoint" nil
))
1252 (read-event nil nil
0.1)))
1254 ;; If `tramp-gvfs-handler-askquestion' has returned "No", it
1255 ;; is marked with the fuse-mountpoint "/". We shall react.
1257 (tramp-get-file-property vec
"/" "fuse-mountpoint" "") "/")
1258 (tramp-error vec
'file-error
"FUSE mount denied"))
1260 ;; We set the connection property "started" in order to put the
1261 ;; remote location into the cache, which is helpful for further
1263 (tramp-set-connection-property vec
"started" t
)))))
1265 (defun tramp-gvfs-send-command (vec command
&rest args
)
1266 "Send the COMMAND with its ARGS to connection VEC.
1267 COMMAND is usually a command from the gvfs-* utilities.
1268 `call-process' is applied, and its return code is returned."
1270 (with-current-buffer (tramp-get-buffer vec
)
1272 (tramp-message vec
6 "%s %s" command
(mapconcat 'identity args
" "))
1273 (setq result
(apply 'tramp-local-call-process command nil t nil args
))
1274 (tramp-message vec
6 "%s" (buffer-string))
1278 ;; D-Bus BLUEZ functions.
1280 (defun tramp-bluez-list-devices ()
1281 "Return all discovered bluetooth devices as list.
1282 Every entry is a list (NAME ADDRESS).
1284 If `tramp-bluez-discover-devices-timeout' is an integer, and the last
1285 discovery happened more time before indicated there, a rescan will be
1286 started, which lasts some ten seconds. Otherwise, cached results will
1288 ;; Reset the scanned devices list if time has passed.
1289 (and (integerp tramp-bluez-discover-devices-timeout
)
1290 (integerp tramp-bluez-discovery
)
1291 (> (tramp-time-diff (current-time) tramp-bluez-discovery
)
1292 tramp-bluez-discover-devices-timeout
)
1293 (setq tramp-bluez-devices nil
))
1295 ;; Rescan if needed.
1296 (unless tramp-bluez-devices
1298 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1299 :system tramp-bluez-service
"/"
1300 tramp-bluez-interface-manager
"DefaultAdapter")))
1301 (setq tramp-bluez-devices nil
1302 tramp-bluez-discovery t
)
1303 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector nil
1304 :system tramp-bluez-service object-path
1305 tramp-bluez-interface-adapter
"StartDiscovery")
1306 (while tramp-bluez-discovery
1307 (read-event nil nil
0.1))))
1308 (setq tramp-bluez-discovery
(current-time))
1309 (tramp-message tramp-gvfs-dbus-event-vector
10 "%s" tramp-bluez-devices
)
1310 tramp-bluez-devices
)
1312 (defun tramp-bluez-property-changed (property value
)
1313 "Signal handler for the \"org.bluez.Adapter.PropertyChanged\" signal."
1314 (tramp-message tramp-gvfs-dbus-event-vector
6 "%s %s" property value
)
1316 ((string-equal property
"Discovering")
1318 ;; "Discovering" FALSE means discovery run has been completed.
1319 ;; We stop it, because we don't need another run.
1320 (setq tramp-bluez-discovery nil
)
1321 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1322 :system tramp-bluez-service
(dbus-event-path-name last-input-event
)
1323 tramp-bluez-interface-adapter
"StopDiscovery")))))
1325 (dbus-register-signal
1326 :system nil nil tramp-bluez-interface-adapter
"PropertyChanged"
1327 'tramp-bluez-property-changed
)
1329 (defun tramp-bluez-device-found (device args
)
1330 "Signal handler for the \"org.bluez.Adapter.DeviceFound\" signal."
1331 (tramp-message tramp-gvfs-dbus-event-vector
6 "%s %s" device args
)
1332 (let ((alias (car (cadr (assoc "Alias" args
))))
1333 (address (car (cadr (assoc "Address" args
)))))
1334 ;; Maybe we shall check the device class for being a proper
1335 ;; device, and call also SDP in order to find the obex service.
1336 (add-to-list 'tramp-bluez-devices
(list alias address
))))
1338 (dbus-register-signal
1339 :system nil nil tramp-bluez-interface-adapter
"DeviceFound"
1340 'tramp-bluez-device-found
)
1342 (defun tramp-bluez-parse-device-names (ignore)
1343 "Return a list of (nil host) tuples allowed to access."
1345 (lambda (x) (list nil
(car x
)))
1346 (tramp-bluez-list-devices)))
1348 ;; Add completion function for OBEX method.
1349 (when (member tramp-bluez-service
(dbus-list-known-names :system
))
1350 (tramp-set-completion-function
1351 "obex" '((tramp-bluez-parse-device-names ""))))
1354 ;; D-Bus zeroconf functions.
1356 (defun tramp-zeroconf-parse-workstation-device-names (ignore)
1357 "Return a list of (user host) tuples allowed to access."
1360 (list nil
(zeroconf-service-host x
)))
1361 (zeroconf-list-services "_workstation._tcp")))
1363 (defun tramp-zeroconf-parse-webdav-device-names (ignore)
1364 "Return a list of (user host) tuples allowed to access."
1367 (let ((host (zeroconf-service-host x
))
1368 (port (zeroconf-service-port x
))
1369 (text (zeroconf-service-txt x
))
1372 (setq host
(format "%s%s%d" host tramp-prefix-port-regexp port
)))
1373 ;; A user is marked in a TXT field like "u=guest".
1375 (when (string-match "u=\\(.+\\)$" (car text
))
1376 (setq user
(match-string 1 (car text
))))
1377 (setq text
(cdr text
)))
1379 (zeroconf-list-services "_webdav._tcp")))
1381 ;; Add completion function for DAV and DAVS methods.
1382 (when (member zeroconf-service-avahi
(dbus-list-known-names :system
))
1383 (zeroconf-init tramp-gvfs-zeroconf-domain
)
1384 (tramp-set-completion-function
1385 "sftp" '((tramp-zeroconf-parse-workstation-device-names "")))
1386 (tramp-set-completion-function
1387 "dav" '((tramp-zeroconf-parse-webdav-device-names "")))
1388 (tramp-set-completion-function
1389 "davs" '((tramp-zeroconf-parse-webdav-device-names ""))))
1392 ;; D-Bus SYNCE functions.
1394 (defun tramp-synce-list-devices ()
1395 "Return all discovered synce devices as list.
1396 They are retrieved from the hal daemon."
1397 (let (tramp-synce-devices)
1399 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1400 :system tramp-hal-service tramp-hal-path-manager
1401 tramp-hal-interface-manager
"GetAllDevices"))
1402 (when (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1403 :system tramp-hal-service device tramp-hal-interface-device
1404 "PropertyExists" "sync.plugin")
1406 'tramp-synce-devices
1407 (with-tramp-dbus-call-method tramp-gvfs-dbus-event-vector t
1408 :system tramp-hal-service device tramp-hal-interface-device
1409 "GetPropertyString" "pda.pocketpc.name"))))
1410 (tramp-message tramp-gvfs-dbus-event-vector
10 "%s" tramp-synce-devices
)
1411 tramp-synce-devices
))
1413 (defun tramp-synce-parse-device-names (ignore)
1414 "Return a list of (nil host) tuples allowed to access."
1416 (lambda (x) (list nil x
))
1417 (tramp-synce-list-devices)))
1419 ;; Add completion function for SYNCE method.
1420 (tramp-set-completion-function
1421 "synce" '((tramp-synce-parse-device-names "")))
1423 (add-hook 'tramp-unload-hook
1425 (unload-feature 'tramp-gvfs
'force
)))
1427 (provide 'tramp-gvfs
)
1431 ;; * Host name completion via smb-server or smb-network.
1432 ;; * Check, how two shares of the same SMB server can be mounted in
1434 ;; * Apply SDP on bluetooth devices, in order to filter out obex
1436 ;; * Implement obex for other serial communication but bluetooth.
1438 ;; arch-tag: f7f660ce-77f4-4132-9663-f5c25a47f7ed
1439 ;;; tramp-gvfs.el ends here