aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2020-01-24 14:41:22 +0100
committerMichael Albinus2020-01-24 14:41:22 +0100
commit984903868bb2fdfadc8f3c08e15434d44c4d08f4 (patch)
tree3ddcfe885b640b7fe5d3f9e52e288f6fae0ae0ac
parent9ba7abe243f0d0c23bc9abca775ae4709dd03030 (diff)
downloademacs-984903868bb2fdfadc8f3c08e15434d44c4d08f4.tar.gz
emacs-984903868bb2fdfadc8f3c08e15434d44c4d08f4.zip
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.
-rw-r--r--lisp/net/tramp-gvfs.el57
1 files changed, 38 insertions, 19 deletions
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index ffcdafcb317..4374dc0a10d 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -687,6 +687,7 @@ It has been changed in GVFS 1.14.")
687 ("gvfs-monitor-file" . "monitor") 687 ("gvfs-monitor-file" . "monitor")
688 ("gvfs-mount" . "mount") 688 ("gvfs-mount" . "mount")
689 ("gvfs-move" . "move") 689 ("gvfs-move" . "move")
690 ("gvfs-rename" . "rename")
690 ("gvfs-rm" . "remove") 691 ("gvfs-rm" . "remove")
691 ("gvfs-set-attribute" . "set") 692 ("gvfs-set-attribute" . "set")
692 ("gvfs-trash" . "trash")) 693 ("gvfs-trash" . "trash"))
@@ -973,11 +974,15 @@ file names."
973 (copy-directory filename newname keep-date t) 974 (copy-directory filename newname keep-date t)
974 (when (eq op 'rename) (delete-directory filename 'recursive))) 975 (when (eq op 'rename) (delete-directory filename 'recursive)))
975 976
976 (let ((t1 (tramp-tramp-file-p filename)) 977 (let* ((t1 (tramp-tramp-file-p filename))
977 (t2 (tramp-tramp-file-p newname)) 978 (t2 (tramp-tramp-file-p newname))
978 (equal-remote (tramp-equal-remote filename newname)) 979 (equal-remote (tramp-equal-remote filename newname))
979 (gvfs-operation (if (eq op 'copy) "gvfs-copy" "gvfs-move")) 980 (gvfs-operation
980 (msg-operation (if (eq op 'copy) "Copying" "Renaming"))) 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")))
981 986
982 (with-parsed-tramp-file-name (if t1 filename newname) nil 987 (with-parsed-tramp-file-name (if t1 filename newname) nil
983 (unless (file-exists-p filename) 988 (unless (file-exists-p filename)
@@ -1048,8 +1053,8 @@ file names."
1048 (filename newname &optional ok-if-already-exists keep-date 1053 (filename newname &optional ok-if-already-exists keep-date
1049 preserve-uid-gid preserve-extended-attributes) 1054 preserve-uid-gid preserve-extended-attributes)
1050 "Like `copy-file' for Tramp files." 1055 "Like `copy-file' for Tramp files."
1051 (setq filename (expand-file-name filename)) 1056 (setq filename (expand-file-name filename)
1052 (setq newname (expand-file-name newname)) 1057 newname (expand-file-name newname))
1053 ;; At least one file a Tramp file? 1058 ;; At least one file a Tramp file?
1054 (if (or (tramp-tramp-file-p filename) 1059 (if (or (tramp-tramp-file-p filename)
1055 (tramp-tramp-file-p newname)) 1060 (tramp-tramp-file-p newname))
@@ -1545,8 +1550,8 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1545 "Like `rename-file' for Tramp files." 1550 "Like `rename-file' for Tramp files."
1546 ;; Check if both files are local -- invoke normal rename-file. 1551 ;; Check if both files are local -- invoke normal rename-file.
1547 ;; Otherwise, use Tramp from local system. 1552 ;; Otherwise, use Tramp from local system.
1548 (setq filename (expand-file-name filename)) 1553 (setq filename (expand-file-name filename)
1549 (setq newname (expand-file-name newname)) 1554 newname (expand-file-name newname))
1550 ;; At least one file a Tramp file? 1555 ;; At least one file a Tramp file?
1551 (if (or (tramp-tramp-file-p filename) 1556 (if (or (tramp-tramp-file-p filename)
1552 (tramp-tramp-file-p newname)) 1557 (tramp-tramp-file-p newname))
@@ -1613,6 +1618,12 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1613 (setq method "davs" 1618 (setq method "davs"
1614 localname 1619 localname
1615 (concat (tramp-gvfs-get-remote-prefix v) localname))) 1620 (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))))
1616 (when (and user domain) 1627 (when (and user domain)
1617 (setq user (concat domain ";" user))) 1628 (setq user (concat domain ";" user)))
1618 (url-recreate-url 1629 (url-recreate-url
@@ -1648,6 +1659,14 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1648 (dbus-unescape-from-identifier 1659 (dbus-unescape-from-identifier
1649 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path))) 1660 (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
1650 1661
1662(defun tramp-gvfs-url-host (url)
1663 "Return the host name part of URL, a string.
1664We cannot use `url-host', because `url-generic-parse-url' returns
1665a downcased host name only."
1666 (and (stringp url)
1667 (string-match "^[[:alnum:]]+://\\([^/:]+\\)" url)
1668 (match-string 1 url)))
1669
1651 1670
1652;; D-Bus GVFS functions. 1671;; D-Bus GVFS functions.
1653 1672
@@ -1788,17 +1807,17 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1788 (when (string-equal "google-drive" method) 1807 (when (string-equal "google-drive" method)
1789 (setq method "gdrive")) 1808 (setq method "gdrive"))
1790 (when (and (string-equal "http" method) (stringp uri)) 1809 (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)
1792 method (url-type uri) 1812 method (url-type uri)
1793 user (url-user uri) 1813 user (url-user uri)
1794 host (url-host uri)
1795 port (url-portspec uri))) 1814 port (url-portspec uri)))
1796 (when (member method tramp-media-methods) 1815 (when (member method tramp-media-methods)
1797 ;; Ensure that media devices are cached. 1816 ;; Ensure that media devices are cached.
1798 (tramp-get-media-devices nil) 1817 (tramp-get-media-devices nil)
1799 (let ((v (tramp-get-connection-property 1818 (let ((v (tramp-get-connection-property
1800 (make-tramp-media-device 1819 (make-tramp-media-device
1801 :method method :host (downcase host) :port port) 1820 :method method :host host :port port)
1802 "vector" nil))) 1821 "vector" nil)))
1803 (when v 1822 (when v
1804 (setq method (tramp-file-name-method v) 1823 (setq method (tramp-file-name-method v)
@@ -1889,17 +1908,17 @@ If FILE-SYSTEM is non-nil, return file system attributes."
1889 (when (string-equal "google-drive" method) 1908 (when (string-equal "google-drive" method)
1890 (setq method "gdrive")) 1909 (setq method "gdrive"))
1891 (when (and (string-equal "http" method) (stringp uri)) 1910 (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)
1893 method (url-type uri) 1913 method (url-type uri)
1894 user (url-user uri) 1914 user (url-user uri)
1895 host (url-host uri)
1896 port (url-portspec uri))) 1915 port (url-portspec uri)))
1897 (when (member method tramp-media-methods) 1916 (when (member method tramp-media-methods)
1898 ;; Ensure that media devices are cached. 1917 ;; Ensure that media devices are cached.
1899 (tramp-get-media-devices vec) 1918 (tramp-get-media-devices vec)
1900 (let ((v (tramp-get-connection-property 1919 (let ((v (tramp-get-connection-property
1901 (make-tramp-media-device 1920 (make-tramp-media-device
1902 :method method :host (downcase host) :port port) 1921 :method method :host host :port port)
1903 "vector" nil))) 1922 "vector" nil)))
1904 (when v 1923 (when v
1905 (setq method (tramp-file-name-method v) 1924 (setq method (tramp-file-name-method v)
@@ -2015,7 +2034,7 @@ and \"org.gtk.Private.RemoteVolumeMonitor.VolumeRemoved\" signals."
2015 :host (replace-regexp-in-string " " "_" (nth 1 volume)))) 2034 :host (replace-regexp-in-string " " "_" (nth 1 volume))))
2016 (media (make-tramp-media-device 2035 (media (make-tramp-media-device
2017 :method method 2036 :method method
2018 :host (url-host uri) 2037 :host (tramp-gvfs-url-host (nth 5 volume))
2019 :port (and (url-portspec uri))))) 2038 :port (and (url-portspec uri)))))
2020 (when (member method tramp-media-methods) 2039 (when (member method tramp-media-methods)
2021 (tramp-message 2040 (tramp-message
@@ -2342,8 +2361,8 @@ It checks for registered GNOME Online Accounts."
2342(defun tramp-get-media-device (vec) 2361(defun tramp-get-media-device (vec)
2343 "Transform VEC into a `tramp-media-device' structure. 2362 "Transform VEC into a `tramp-media-device' structure.
2344Check, that respective cache values do exist." 2363Check, that respective cache values do exist."
2345 (if-let* ((media (tramp-get-connection-property vec "media-device" nil)) 2364 (if-let ((media (tramp-get-connection-property vec "media-device" nil))
2346 (prop (tramp-get-connection-property media "vector" nil))) 2365 (prop (tramp-get-connection-property media "vector" nil)))
2347 media 2366 media
2348 (tramp-get-media-devices vec) 2367 (tramp-get-media-devices vec)
2349 (tramp-get-connection-property vec "media-device" nil))) 2368 (tramp-get-connection-property vec "media-device" nil)))
@@ -2365,7 +2384,7 @@ VEC is used only for traces."
2365 :host (replace-regexp-in-string " " "_" (nth 1 volume)))) 2384 :host (replace-regexp-in-string " " "_" (nth 1 volume))))
2366 (media (make-tramp-media-device 2385 (media (make-tramp-media-device
2367 :method method 2386 :method method
2368 :host (url-host uri) 2387 :host (tramp-gvfs-url-host (nth 5 volume))
2369 :port (and (url-portspec uri) 2388 :port (and (url-portspec uri)
2370 (number-to-string (url-portspec uri)))))) 2389 (number-to-string (url-portspec uri))))))
2371 (push (tramp-file-name-host vec) devices) 2390 (push (tramp-file-name-host vec) devices)