Function: tramp-sshfs-maybe-open-connection

tramp-sshfs-maybe-open-connection is a byte-compiled function defined in tramp-sshfs.el.gz.

Signature

(tramp-sshfs-maybe-open-connection VEC)

Documentation

Maybe open a connection VEC.

Does not do anything if a connection is already open, but re-opens the connection if a previous connection has died for some reason.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sshfs.el.gz
;; File name conversions.

(defun tramp-sshfs-maybe-open-connection (vec)
  "Maybe open a connection VEC.
Does not do anything if a connection is already open, but re-opens the
connection if a previous connection has died for some reason."
  ;; During completion, don't reopen a new connection.
  (unless (tramp-connectable-p vec)
    (throw 'non-essential 'non-essential))

  ;; We need a process bound to the connection buffer.  Therefore, we
  ;; create a dummy process.  Maybe there is a better solution?
  (unless (get-buffer-process (tramp-get-connection-buffer vec))
    (let ((p (make-network-process
	      :name (tramp-get-connection-name vec)
	      :buffer (tramp-get-connection-buffer vec)
	      :server t :host 'local :service t :noquery t)))
      (process-put p 'tramp-vector vec)
      (set-process-query-on-exit-flag p nil)

      ;; Set connection-local variables.
      (tramp-set-connection-local-variables vec)))

  ;; Create directory.
  (unless (file-directory-p (tramp-fuse-mount-point vec))
    (make-directory (tramp-fuse-mount-point vec) 'parents))

  (unless
      (or (tramp-fuse-mounted-p vec)
	  (with-temp-buffer
	    (zerop
	     (apply
	      #'tramp-call-process
	      vec tramp-sshfs-program nil t nil
	      (tramp-fuse-mount-spec vec)
	      (tramp-fuse-mount-point vec)
	      (tramp-expand-args
	       vec 'tramp-mount-args
	       ?p (or (tramp-file-name-port vec) ""))))))
    (tramp-error
     vec 'file-error "Error mounting %s" (tramp-fuse-mount-spec vec)))

  ;; Mark it as connected.
  (add-to-list 'tramp-fuse-mount-points (tramp-file-name-unify vec))
  (tramp-set-connection-property
   (tramp-get-connection-process vec) "connected" t)

  ;; In `tramp-check-cached-permissions', the connection properties
  ;; "{uid,gid}-{integer,string}" are used.  We set them to proper values.
  (with-tramp-connection-property
      vec "uid-integer" (tramp-get-local-uid 'integer))
  (with-tramp-connection-property
      vec "gid-integer" (tramp-get-local-gid 'integer))
  (with-tramp-connection-property
      vec "uid-string" (tramp-get-local-uid 'string))
  (with-tramp-connection-property
      vec "gid-string" (tramp-get-local-gid 'string)))