Skip to content

Commit 9849038

Browse files
committed
Support (un)mount of Tramp media devices
* lisp/net/tramp-gvfs.el (tramp-gvfs-gio-mapping): Add "gvfs-rename". (tramp-gvfs-do-copy-or-rename-file): Use it. (tramp-gvfs-activation-uri): Handle "media" method. (tramp-gvfs-url-host): New defun. (tramp-gvfs-handler-mounted-unmounted) (tramp-gvfs-connection-mounted-p) (tramp-gvfs-handler-volumeadded-volumeremoved) (tramp-get-media-devices): Use it.
1 parent 9ba7abe commit 9849038

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

lisp/net/tramp-gvfs.el

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ It has been changed in GVFS 1.14.")
687687
("gvfs-monitor-file" . "monitor")
688688
("gvfs-mount" . "mount")
689689
("gvfs-move" . "move")
690+
("gvfs-rename" . "rename")
690691
("gvfs-rm" . "remove")
691692
("gvfs-set-attribute" . "set")
692693
("gvfs-trash" . "trash"))
@@ -973,11 +974,15 @@ file names."
973974
(copy-directory filename newname keep-date t)
974975
(when (eq op 'rename) (delete-directory filename 'recursive)))
975976

976-
(let ((t1 (tramp-tramp-file-p filename))
977-
(t2 (tramp-tramp-file-p newname))
978-
(equal-remote (tramp-equal-remote filename newname))
979-
(gvfs-operation (if (eq op 'copy) "gvfs-copy" "gvfs-move"))
980-
(msg-operation (if (eq op 'copy) "Copying" "Renaming")))
977+
(let* ((t1 (tramp-tramp-file-p filename))
978+
(t2 (tramp-tramp-file-p newname))
979+
(equal-remote (tramp-equal-remote filename newname))
980+
(gvfs-operation
981+
(cond
982+
((eq op 'copy) "gvfs-copy")
983+
(equal-remote "gvfs-rename")
984+
(t "gvfs-move")))
985+
(msg-operation (if (eq op 'copy) "Copying" "Renaming")))
981986

982987
(with-parsed-tramp-file-name (if t1 filename newname) nil
983988
(unless (file-exists-p filename)
@@ -1048,8 +1053,8 @@ file names."
10481053
(filename newname &optional ok-if-already-exists keep-date
10491054
preserve-uid-gid preserve-extended-attributes)
10501055
"Like `copy-file' for Tramp files."
1051-
(setq filename (expand-file-name filename))
1052-
(setq newname (expand-file-name newname))
1056+
(setq filename (expand-file-name filename)
1057+
newname (expand-file-name newname))
10531058
;; At least one file a Tramp file?
10541059
(if (or (tramp-tramp-file-p filename)
10551060
(tramp-tramp-file-p newname))
@@ -1545,8 +1550,8 @@ If FILE-SYSTEM is non-nil, return file system attributes."
15451550
"Like `rename-file' for Tramp files."
15461551
;; Check if both files are local -- invoke normal rename-file.
15471552
;; Otherwise, use Tramp from local system.
1548-
(setq filename (expand-file-name filename))
1549-
(setq newname (expand-file-name newname))
1553+
(setq filename (expand-file-name filename)
1554+
newname (expand-file-name newname))
15501555
;; At least one file a Tramp file?
15511556
(if (or (tramp-tramp-file-p filename)
15521557
(tramp-tramp-file-p newname))
@@ -1613,6 +1618,12 @@ If FILE-SYSTEM is non-nil, return file system attributes."
16131618
(setq method "davs"
16141619
localname
16151620
(concat (tramp-gvfs-get-remote-prefix v) localname)))
1621+
(when (string-equal "media" method)
1622+
(when-let
1623+
((media (tramp-get-connection-property v "media-device" nil)))
1624+
(setq method (tramp-media-device-method media)
1625+
host (tramp-media-device-host media)
1626+
port (tramp-media-device-port media))))
16161627
(when (and user domain)
16171628
(setq user (concat domain ";" user)))
16181629
(url-recreate-url
@@ -1648,6 +1659,14 @@ If FILE-SYSTEM is non-nil, return file system attributes."
16481659
(dbus-unescape-from-identifier
16491660
(replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
16501661

1662+
(defun tramp-gvfs-url-host (url)
1663+
"Return the host name part of URL, a string.
1664+
We cannot use `url-host', because `url-generic-parse-url' returns
1665+
a downcased host name only."
1666+
(and (stringp url)
1667+
(string-match "^[[:alnum:]]+://\\([^/:]+\\)" url)
1668+
(match-string 1 url)))
1669+
16511670

16521671
;; D-Bus GVFS functions.
16531672

@@ -1788,17 +1807,17 @@ If FILE-SYSTEM is non-nil, return file system attributes."
17881807
(when (string-equal "google-drive" method)
17891808
(setq method "gdrive"))
17901809
(when (and (string-equal "http" method) (stringp uri))
1791-
(setq uri (url-generic-parse-url uri)
1810+
(setq host (tramp-gvfs-url-host uri)
1811+
uri (url-generic-parse-url uri)
17921812
method (url-type uri)
17931813
user (url-user uri)
1794-
host (url-host uri)
17951814
port (url-portspec uri)))
17961815
(when (member method tramp-media-methods)
17971816
;; Ensure that media devices are cached.
17981817
(tramp-get-media-devices nil)
17991818
(let ((v (tramp-get-connection-property
18001819
(make-tramp-media-device
1801-
:method method :host (downcase host) :port port)
1820+
:method method :host host :port port)
18021821
"vector" nil)))
18031822
(when v
18041823
(setq method (tramp-file-name-method v)
@@ -1889,17 +1908,17 @@ If FILE-SYSTEM is non-nil, return file system attributes."
18891908
(when (string-equal "google-drive" method)
18901909
(setq method "gdrive"))
18911910
(when (and (string-equal "http" method) (stringp uri))
1892-
(setq uri (url-generic-parse-url uri)
1911+
(setq host (tramp-gvfs-url-host uri)
1912+
uri (url-generic-parse-url uri)
18931913
method (url-type uri)
18941914
user (url-user uri)
1895-
host (url-host uri)
18961915
port (url-portspec uri)))
18971916
(when (member method tramp-media-methods)
18981917
;; Ensure that media devices are cached.
18991918
(tramp-get-media-devices vec)
19001919
(let ((v (tramp-get-connection-property
19011920
(make-tramp-media-device
1902-
:method method :host (downcase host) :port port)
1921+
:method method :host host :port port)
19031922
"vector" nil)))
19041923
(when v
19051924
(setq method (tramp-file-name-method v)
@@ -2015,7 +2034,7 @@ and \"org.gtk.Private.RemoteVolumeMonitor.VolumeRemoved\" signals."
20152034
:host (replace-regexp-in-string " " "_" (nth 1 volume))))
20162035
(media (make-tramp-media-device
20172036
:method method
2018-
:host (url-host uri)
2037+
:host (tramp-gvfs-url-host (nth 5 volume))
20192038
:port (and (url-portspec uri)))))
20202039
(when (member method tramp-media-methods)
20212040
(tramp-message
@@ -2342,8 +2361,8 @@ It checks for registered GNOME Online Accounts."
23422361
(defun tramp-get-media-device (vec)
23432362
"Transform VEC into a `tramp-media-device' structure.
23442363
Check, that respective cache values do exist."
2345-
(if-let* ((media (tramp-get-connection-property vec "media-device" nil))
2346-
(prop (tramp-get-connection-property media "vector" nil)))
2364+
(if-let ((media (tramp-get-connection-property vec "media-device" nil))
2365+
(prop (tramp-get-connection-property media "vector" nil)))
23472366
media
23482367
(tramp-get-media-devices vec)
23492368
(tramp-get-connection-property vec "media-device" nil)))
@@ -2365,7 +2384,7 @@ VEC is used only for traces."
23652384
:host (replace-regexp-in-string " " "_" (nth 1 volume))))
23662385
(media (make-tramp-media-device
23672386
:method method
2368-
:host (url-host uri)
2387+
:host (tramp-gvfs-url-host (nth 5 volume))
23692388
:port (and (url-portspec uri)
23702389
(number-to-string (url-portspec uri))))))
23712390
(push (tramp-file-name-host vec) devices)

0 commit comments

Comments
 (0)