[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tramp with sshfs

From: Mihai Lutescu
Subject: Re: Tramp with sshfs
Date: Wed, 18 Aug 2010 14:40:49 +0000 (UTC)
User-agent: Loom/3.14 (


That's exactly what I did the last weekend.

I crafted a toy tramp method that I called `ext', because it relays on
an 'external' mount method for most operations that deal with files.
That may be sshfs or whatever else.

My feeling is, that method is much faster then scp or other tramp method
that I tried. 

My implementation mounts sillently a directory "/tmp/address@hidden" to the
remote path "/ext:address@hidden:/".  That mapping is hardcoded right now,
but it's trivial to change it.

The only problem that I found after a few days of using it is the
expansion of "~" in remote paths like "/ext:address@hidden:~/".  That would
not too be to difficult to fix too, but requires to think about how to
map home directories to '/ext:' paths, which I was to lazy to.  For now
using a '~' will map to your local home directory.

Find bellow the 'tramp-ext.el' method.

If you want to try that stuff, don't forget to modify mine
`tramp-login-program'.  (I use to use an expect script to launch
external processes)

I'm interested in your feedback.  If there is interest I could
volonteer to maintain it.

Best regards,
Mihai LuĹŁescu

;; ----------------------------
;; external tramp method '/ext:'
;; -----------------------------

;; That's an external tramp method which allows 'external' mounting
;; mechanisms (a la 'sshfs') to be employed, while retaining the
;; default magic to deal with remote processes.

(require 'tramp)
(require 'cl)

(add-to-list 'tramp-foreign-file-name-handler-alist
             (cons 'tramp-ext-file-name-p 'tramp-ext-file-name-handler))

(add-to-list 'tramp-methods '("ext"
                              (tramp-login-program "~/local/bin/login.exp") 
                              (tramp-login-args (("login") ("%h") ("%u") ))
                              (tramp-remote-sh "/bin/sh")                       

(defun tramp-ext-file-name-p (filename)
  "Check if it's a filename for EXT protocol."
  (let ((v (tramp-dissect-file-name filename)))
    (string= (tramp-file-name-method v) "ext")))

(defun rtl (something)
  "rtl == remote-to-local.  Transform all occurences of a remote
path in something, to it's local contrapart"

   ((stringp something)
         (replace-regexp-in-string "^/ext:\\([^:]+\\):" "/tmp/\\1" something))
    ((listp something)
     (mapcar 'rtl something))
(defun ltr (something)
  "'local to remote', the oposite of `rtl'."
   ((stringp something)
    (replace-regexp-in-string  "/tmp/\\([^/]+\\)" "/ext:\\1:" something))
    ((listp something)
     (mapcar 'ltr something))
(defun tramp-ext-delegate-to-default (operation args)
  "most file-name operations are delegated to the default
  handlers, than the result is transformed back to remote file

  To ensure proper functioning of the default handlers,
  `default-directory' and `buffer-file-name' are also tranformed
  from remote to their local equivalent "

  (let ((default-directory (rtl default-directory))
        (buffer-file-name  (rtl buffer-file-name)))
     (apply (symbol-function operation) 
            (rtl args)))))

(defun tramp-ext-file-name-handler (operation &rest args)

   ((equal 'insert-file-contents operation)
    (when (second args)
      (setq buffer-file-name (expand-file-name filename))
      (set-buffer-modified-p nil))
    (tramp-ext-delegate-to-default 'insert-file-contents args)
   ((equal 'start-file-process operation)
    (apply 'tramp-handle-start-file-process args))
   ((equal 'file-remote-p operation)
    (apply 'tramp-handle-file-remote-p args))
   ((equal 'verify-visited-file-modtime  operation)
    ;; ignore
    (tramp-ext-delegate-to-default operation args))))

(provide 'tramp-ext)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]