Michael Albinus <[email protected]> writes:
Hi Stephen,
> I'll tell you later (today?) when I have pushed something.
Try the appended patch. There's a new user option
`tramp-fuse-unmount-on-cleanup'. When set to non-nil, Tramp shall
unmount the fuse volumes it has mounted itself.
Best regards, Michael.
diff --git a/lisp/tramp-fuse.el b/lisp/tramp-fuse.el
index 8c5afa7c..cf5af234 100644
--- a/lisp/tramp-fuse.el
+++ b/lisp/tramp-fuse.el
@@ -175,13 +175,26 @@
mount)
(match-string 1 mount)))))))
+(defun tramp-fuse-get-fusermount ()
+ "Determine the local `fusermount' command."
+ ;; We use key nil for local connection properties.
+ (with-tramp-connection-property nil "fusermount"
+ (or (executable-find "fusermount3")
+ (executable-find "fusermount"))))
+
+(defvar tramp-fuse-mount-points nil
+ "List of fuse volume determined by a VEC.")
+
(defun tramp-fuse-unmount (vec)
"Unmount fuse volume determined by VEC."
(let ((default-directory tramp-compat-temporary-file-directory)
- (command (format "fusermount3 -u %s" (tramp-fuse-mount-point vec))))
+ (command
+ (format
+ "%s -u %s" (tramp-fuse-get-fusermount) (tramp-fuse-mount-point vec))))
(tramp-message vec 6 "%s\n%s" command (shell-command-to-string command))
(tramp-flush-connection-property
(tramp-get-connection-process vec) "mounted")
+ (setq tramp-fuse-mount-points (delete vec tramp-fuse-mount-points))
;; Give the caches a chance to expire.
(sleep-for 1)))
@@ -205,6 +218,36 @@
(substring localname 1) localname)
(tramp-fuse-mount-point v)))))))
+(defcustom tramp-fuse-unmount-on-cleanup nil
+ "Whether fuse volumes shall be unmounted on cleanup."
+ :group 'tramp
+ :version "28.1"
+ :type 'boolean)
+
+(defun tramp-fuse-cleanup (vec)
+ "Cleanup fuse volume determined by VEC."
+ (and tramp-fuse-unmount-on-cleanup
+ (member vec tramp-fuse-mount-points)
+ (tramp-fuse-unmount vec)))
+
+(defun tramp-fuse-cleanup-all ()
+ "Unmount all fuse volumes used by Tramp."
+ (and tramp-fuse-unmount-on-cleanup
+ (mapc #'tramp-fuse-unmount tramp-fuse-mount-points)))
+
+;; Add cleanup hooks.
+(add-hook 'tramp-cleanup-connection-hook #'tramp-fuse-cleanup)
+(add-hook 'tramp-cleanup-all-connections-hook #'tramp-fuse-cleanup-all)
+(add-hook 'kill-emacs-hook #'tramp-fuse-cleanup-all)
+(add-hook 'tramp-fuse-unload-hook
+ (lambda ()
+ (remove-hook 'tramp-cleanup-connection-hook
+ #'tramp-fuse-cleanup)
+ (remove-hook 'tramp-cleanup-all-connections-hook
+ #'tramp-fuse-cleanup-all)
+ (remove-hook 'kill-emacs-hook
+ #'tramp-fuse-cleanup-all)))
+
(add-hook 'tramp-unload-hook
(lambda ()
(unload-feature 'tramp-fuse 'force)))
diff --git a/lisp/tramp-rclone.el b/lisp/tramp-rclone.el
index 49e366c0..e9d9b4e3 100644
--- a/lisp/tramp-rclone.el
+++ b/lisp/tramp-rclone.el
@@ -386,6 +386,7 @@ connection if a previous connection has died for some reason."
(tramp-cleanup-connection vec 'keep-debug 'keep-password))
;; Mark it as connected.
+ (add-to-list 'tramp-fuse-mount-points vec)
(tramp-set-connection-property
(tramp-get-connection-process vec) "connected" t))))
diff --git a/lisp/tramp-sshfs.el b/lisp/tramp-sshfs.el
index 0019ac01..266e4039 100644
--- a/lisp/tramp-sshfs.el
+++ b/lisp/tramp-sshfs.el
@@ -368,6 +368,7 @@ connection if a previous connection has died for some reason."
vec 'file-error "Error mounting %s" (tramp-fuse-mount-spec vec))))
;; Mark it as connected.
+ (add-to-list 'tramp-fuse-mount-points vec)
(tramp-set-connection-property
(tramp-get-connection-process vec) "connected" t)))