diff options
Diffstat (limited to 'lisp/net/tramp-fuse.el')
-rw-r--r-- | lisp/net/tramp-fuse.el | 80 |
1 files changed, 66 insertions, 14 deletions
diff --git a/lisp/net/tramp-fuse.el b/lisp/net/tramp-fuse.el index 93b184a36c2..c359082dc1e 100644 --- a/lisp/net/tramp-fuse.el +++ b/lisp/net/tramp-fuse.el @@ -154,36 +154,58 @@ (when (tramp-file-name-user vec) (concat (tramp-file-name-user-domain vec) "@")) (tramp-file-name-host-port vec)) - (tramp-compat-temporary-file-directory)))) + tramp-compat-temporary-file-directory))) + +(defconst tramp-fuse-mount-timeout + (eval (car (get 'remote-file-name-inhibit-cache 'standard-value)) t) + "Time period to check whether the mount point still exists. +It has the same meaning as `remote-file-name-inhibit-cache'.") (defun tramp-fuse-mounted-p (vec) "Check, whether fuse volume determined by VEC is mounted." - (when (tramp-get-connection-process vec) - ;; We cannot use `with-connection-property', because we don't want - ;; to cache a nil result. - (or (tramp-get-connection-property - (tramp-get-connection-process vec) "mounted" nil) - (let* ((default-directory (tramp-compat-temporary-file-directory)) + ;; Remember the mount status by using a file property on "/", + ;; instead of using a connection property, because a file property + ;; has a timeout. Having a timeout lets us regularly recheck the + ;; mount status, as requested by `tramp-fuse-mount-timeout'. We + ;; cannot use `with-tramp-file-property', because we don't want to + ;; cache a nil result. + (let ((remote-file-name-inhibit-cache tramp-fuse-mount-timeout)) + (or (tramp-get-file-property vec "/" "mounted" nil) + (let* ((default-directory tramp-compat-temporary-file-directory) (command (format "mount -t fuse.%s" (tramp-file-name-method vec))) (mount (shell-command-to-string command))) (tramp-message vec 6 "%s\n%s" command mount) - (tramp-set-connection-property - (tramp-get-connection-process vec) "mounted" + (tramp-set-file-property + vec "/" "mounted" (when (string-match (format "^\\(%s\\)\\s-" (regexp-quote (tramp-fuse-mount-spec vec))) 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)))) + (let* ((default-directory tramp-compat-temporary-file-directory) + (mount-point (tramp-fuse-mount-point vec)) + (command (format "%s -u %s" (tramp-fuse-get-fusermount) mount-point))) (tramp-message vec 6 "%s\n%s" command (shell-command-to-string command)) - (tramp-flush-connection-property - (tramp-get-connection-process vec) "mounted") + (tramp-flush-file-property vec "/" "mounted") + (setq tramp-fuse-mount-points + (delete (tramp-file-name-unify vec) tramp-fuse-mount-points)) ;; Give the caches a chance to expire. - (sleep-for 1))) + (sleep-for 1) + (when (tramp-compat-directory-empty-p mount-point) + (delete-directory mount-point)))) (defun tramp-fuse-local-file-name (filename) "Return local mount name of FILENAME." @@ -205,6 +227,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 (tramp-file-name-unify 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))) |