Commit 3675b169 authored by Michael Albinus's avatar Michael Albinus
Browse files

Major rewrite due to changed D-Bus interface of GVFS 1.14.

* net/tramp-gvfs.el (top): Extend check for gvfs availability.
(tramp-gvfs-methods-mounttracker, tramp-gvfs-listmounts)
(tramp-gvfs-mountlocation, tramp-gvfs-mountlocation-signature):
New defconst.
(tramp-gvfs-file-name-handler-alist) [directory-files]:
[directory-files-and-attributes, file-exists-p, file-modes]: Use
Tramp default handler.
[file-acl, file-selinux-context, process-file, set-file-acl]:
[set-file-modes, set-file-selinux-context, shell-command]:
[start-file-process ]: Remove handler.
[verify-visited-file-modtime]: New handler.
(tramp-gvfs-dbus-string-to-byte-array)
(tramp-gvfs-dbus-byte-array-to-string): New defuns.  Replace all
calls of `dbus-string-to-byte-array' and
`tramp-gvfs-dbus-byte-array-to-string'.
(tramp-gvfs-handle-copy-file)
(tramp-gvfs-handle-delete-directory)
(tramp-gvfs-handle-delete-file, tramp-gvfs-handle-file-attributes)
(tramp-gvfs-handle-file-directory-p)
(tramp-gvfs-handle-file-executable-p)
(tramp-gvfs-handle-file-name-all-completions)
(tramp-gvfs-handle-file-readable-p)
(tramp-gvfs-handle-file-writable-p)
(tramp-gvfs-handle-insert-directory)
(tramp-gvfs-handle-insert-file-contents)
(tramp-gvfs-handle-make-directory, tramp-gvfs-handle-rename-file)
(tramp-gvfs-handle-set-visited-file-modtime)
(tramp-gvfs-handle-write-region): Rewrite.
(tramp-gvfs-handle-file-acl)
(tramp-gvfs-handle-file-selinux-context)
(tramp-gvfs-handle-process-file, tramp-gvfs-handle-set-file-acl)
(tramp-gvfs-handle-set-file-modes)
(tramp-gvfs-handle-set-file-selinux-context)
(tramp-gvfs-handle-shell-command)
(tramp-gvfs-handle-start-file-process)
(tramp-gvfs-handle-verify-visited-file-modtime): Remove defuns.
(tramp-gvfs-url-file-name): Do not use `file-truename', we work
over the symlinks.  Fix user handling.
(top, tramp-gvfs-handler-mounted-unmounted): Handle different names
of the D-Bus signals.
(tramp-gvfs-connection-mounted-p): Handle different names of the
D-Bus methods.
(tramp-gvfs-mount-spec-entry): New defun.
(tramp-gvfs-mount-spec): Use it.
(tramp-gvfs-maybe-open-connection): Check, that in case of "smb"
there is a share name.  Handle different names of the D-Bus
signals and methods.
(tramp-gvfs-maybe-open-connection): Set connection properties
needed for `tramp-check-cached-permissions'.
(tramp-gvfs-send-command): Apply `tramp-gvfs-maybe-open-connection'.
Return t or nil.

* net/tramp.el (tramp-backtrace): Move up.
(tramp-error): Apply a backtrace into the debug buffer when
`tramp-verbose > 9.
(tramp-file-mode-type-map, tramp-file-mode-from-int)
(tramp-file-mode-permissions, tramp-get-local-uid)
(tramp-get-local-gid, tramp-check-cached-permissions): Move from
tramp-sh.el.

* net/tramp-sh.el (tramp-file-mode-type-map)
(tramp-check-cached-permissions, tramp-file-mode-from-int)
(tramp-file-mode-permissions, tramp-get-local-uid)
(tramp-get-local-gid): Move to tramp.el.
parent 27a98a62
2013-03-09 Michael Albinus <michael.albinus@gmx.de>
Major rewrite due to changed D-Bus interface of GVFS 1.14.
* net/tramp-gvfs.el (top): Extend check for gvfs availability.
(tramp-gvfs-methods-mounttracker, tramp-gvfs-listmounts)
(tramp-gvfs-mountlocation, tramp-gvfs-mountlocation-signature):
New defconst.
(tramp-gvfs-file-name-handler-alist) [directory-files]:
[directory-files-and-attributes, file-exists-p, file-modes]: Use
Tramp default handler.
[file-acl, file-selinux-context, process-file, set-file-acl]:
[set-file-modes, set-file-selinux-context, shell-command]:
[start-file-process ]: Remove handler.
[verify-visited-file-modtime]: New handler.
(tramp-gvfs-dbus-string-to-byte-array)
(tramp-gvfs-dbus-byte-array-to-string): New defuns. Replace all
calls of `dbus-string-to-byte-array' and
`tramp-gvfs-dbus-byte-array-to-string'.
(tramp-gvfs-handle-copy-file)
(tramp-gvfs-handle-delete-directory)
(tramp-gvfs-handle-delete-file, tramp-gvfs-handle-file-attributes)
(tramp-gvfs-handle-file-directory-p)
(tramp-gvfs-handle-file-executable-p)
(tramp-gvfs-handle-file-name-all-completions)
(tramp-gvfs-handle-file-readable-p)
(tramp-gvfs-handle-file-writable-p)
(tramp-gvfs-handle-insert-directory)
(tramp-gvfs-handle-insert-file-contents)
(tramp-gvfs-handle-make-directory, tramp-gvfs-handle-rename-file)
(tramp-gvfs-handle-set-visited-file-modtime)
(tramp-gvfs-handle-write-region): Rewrite.
(tramp-gvfs-handle-file-acl)
(tramp-gvfs-handle-file-selinux-context)
(tramp-gvfs-handle-process-file, tramp-gvfs-handle-set-file-acl)
(tramp-gvfs-handle-set-file-modes)
(tramp-gvfs-handle-set-file-selinux-context)
(tramp-gvfs-handle-shell-command)
(tramp-gvfs-handle-start-file-process)
(tramp-gvfs-handle-verify-visited-file-modtime): Remove defuns.
(tramp-gvfs-url-file-name): Do not use `file-truename', we work
over the symlinks. Fix user handling.
(top, tramp-gvfs-handler-mounted-unmounted): Handle different names
of the D-Bus signals.
(tramp-gvfs-connection-mounted-p): Handle different names of the
D-Bus methods.
(tramp-gvfs-mount-spec-entry): New defun.
(tramp-gvfs-mount-spec): Use it.
(tramp-gvfs-maybe-open-connection): Check, that in case of "smb"
there is a share name. Handle different names of the D-Bus
signals and methods.
(tramp-gvfs-maybe-open-connection): Set connection properties
needed for `tramp-check-cached-permissions'.
(tramp-gvfs-send-command): Apply `tramp-gvfs-maybe-open-connection'.
Return t or nil.
* net/tramp.el (tramp-backtrace): Move up.
(tramp-error): Apply a backtrace into the debug buffer when
`tramp-verbose > 9.
(tramp-file-mode-type-map, tramp-file-mode-from-int)
(tramp-file-mode-permissions, tramp-get-local-uid)
(tramp-get-local-gid, tramp-check-cached-permissions): Move from
tramp-sh.el.
* net/tramp-sh.el (tramp-file-mode-type-map)
(tramp-check-cached-permissions, tramp-file-mode-from-int)
(tramp-file-mode-permissions, tramp-get-local-uid)
(tramp-get-local-gid): Move to tramp.el.
2013-03-09 Stefan Monnier <monnier@iro.umontreal.ca>
 
Separate mouse-1-click-follows-link from mouse-drag-region.
......
This diff is collapsed.
......@@ -788,25 +788,6 @@ existence, and file readability. Input shall be read via
here-document, otherwise the command could exceed maximum length
of command line.")
(defconst tramp-file-mode-type-map
'((0 . "-") ; Normal file (SVID-v2 and XPG2)
(1 . "p") ; fifo
(2 . "c") ; character device
(3 . "m") ; multiplexed character device (v7)
(4 . "d") ; directory
(5 . "?") ; Named special file (XENIX)
(6 . "b") ; block device
(7 . "?") ; multiplexed block device (v7)
(8 . "-") ; regular file
(9 . "n") ; network special file (HP-UX)
(10 . "l") ; symlink
(11 . "?") ; ACL shadow inode (Solaris, not userspace)
(12 . "s") ; socket
(13 . "D") ; door special (Solaris)
(14 . "w")) ; whiteout (BSD)
"A list of file types returned from the `stat' system call.
This is used to map a mode number to a permission string.")
;; New handlers should be added here. The following operations can be
;; handled using the normal primitives: file-name-sans-versions,
;; get-file-buffer.
......@@ -4654,76 +4635,6 @@ Return ATTR."
(tramp-get-device vec))
attr))
(defun tramp-check-cached-permissions (vec access)
"Check `file-attributes' caches for VEC.
Return t if according to the cache access type ACCESS is known to
be granted."
(let ((result nil)
(offset (cond
((eq ?r access) 1)
((eq ?w access) 2)
((eq ?x access) 3))))
(dolist (suffix '("string" "integer") result)
(setq
result
(or
result
(let ((file-attr
(tramp-get-file-property
vec (tramp-file-name-localname vec)
(concat "file-attributes-" suffix) nil))
(remote-uid
(tramp-get-connection-property
vec (concat "uid-" suffix) nil))
(remote-gid
(tramp-get-connection-property
vec (concat "gid-" suffix) nil)))
(and
file-attr
(or
;; Not a symlink
(eq t (car file-attr))
(null (car file-attr)))
(or
;; World accessible.
(eq access (aref (nth 8 file-attr) (+ offset 6)))
;; User accessible and owned by user.
(and
(eq access (aref (nth 8 file-attr) offset))
(equal remote-uid (nth 2 file-attr)))
;; Group accessible and owned by user's
;; principal group.
(and
(eq access (aref (nth 8 file-attr) (+ offset 3)))
(equal remote-gid (nth 3 file-attr)))))))))))
(defun tramp-file-mode-from-int (mode)
"Turn an integer representing a file mode into an ls(1)-like string."
(let ((type (cdr
(assoc (logand (lsh mode -12) 15) tramp-file-mode-type-map)))
(user (logand (lsh mode -6) 7))
(group (logand (lsh mode -3) 7))
(other (logand (lsh mode -0) 7))
(suid (> (logand (lsh mode -9) 4) 0))
(sgid (> (logand (lsh mode -9) 2) 0))
(sticky (> (logand (lsh mode -9) 1) 0)))
(setq user (tramp-file-mode-permissions user suid "s"))
(setq group (tramp-file-mode-permissions group sgid "s"))
(setq other (tramp-file-mode-permissions other sticky "t"))
(concat type user group other)))
(defun tramp-file-mode-permissions (perm suid suid-text)
"Convert a permission bitset into a string.
This is used internally by `tramp-file-mode-from-int'."
(let ((r (> (logand perm 4) 0))
(w (> (logand perm 2) 0))
(x (> (logand perm 1) 0)))
(concat (or (and r "r") "-")
(or (and w "w") "-")
(or (and suid x suid-text) ; suid, execute
(and suid (upcase suid-text)) ; suid, !execute
(and x "x") "-")))) ; !suid
(defun tramp-shell-case-fold (string)
"Converts STRING to shell glob pattern which ignores case."
(mapconcat
......@@ -4992,14 +4903,6 @@ This is used internally by `tramp-file-mode-from-int'."
;; The command might not always return a number.
(if (and (equal id-format 'integer) (not (integerp res))) -1 res))))
(defun tramp-get-local-uid (id-format)
(if (equal id-format 'integer) (user-uid) (user-login-name)))
(defun tramp-get-local-gid (id-format)
(if (and (fboundp 'group-gid) (equal id-format 'integer))
(tramp-compat-funcall 'group-gid)
(nth 3 (tramp-compat-file-attributes "~/" id-format))))
;; Some predefined connection properties.
(defun tramp-get-inline-compress (vec prop size)
"Return the compress command related to PROP.
......
......@@ -1505,12 +1505,18 @@ applicable)."
(concat (format "(%d) # " level) fmt-string)
args)))))))
(defsubst tramp-backtrace (vec-or-proc)
"Dump a backtrace into the debug buffer.
This function is meant for debugging purposes."
(tramp-message vec-or-proc 10 "\n%s" (with-output-to-string (backtrace))))
(defsubst tramp-error (vec-or-proc signal fmt-string &rest args)
"Emit an error.
VEC-OR-PROC identifies the connection to use, SIGNAL is the
signal identifier to be raised, remaining args passed to
`tramp-message'. Finally, signal SIGNAL is raised."
(let (tramp-message-show-message)
(tramp-backtrace vec-or-proc)
(tramp-message
vec-or-proc 1 "%s"
(error-message-string
......@@ -1543,11 +1549,6 @@ an input event arrives. The other arguments are passed to `tramp-error'."
"`M-x tramp-cleanup-this-connection'"))
(sit-for 30))))))
(defsubst tramp-backtrace (vec-or-proc)
"Dump a backtrace into the debug buffer.
This function is meant for debugging purposes."
(tramp-message vec-or-proc 10 "\n%s" (with-output-to-string (backtrace))))
(defmacro with-parsed-tramp-file-name (filename var &rest body)
"Parse a Tramp filename and make components available in the body.
......@@ -3660,6 +3661,107 @@ would yield `t'. On the other hand, the following check results in nil:
(t (error "Tenth char `%c' must be one of `xtT-'"
other-execute-or-sticky)))))))
(defconst tramp-file-mode-type-map
'((0 . "-") ; Normal file (SVID-v2 and XPG2)
(1 . "p") ; fifo
(2 . "c") ; character device
(3 . "m") ; multiplexed character device (v7)
(4 . "d") ; directory
(5 . "?") ; Named special file (XENIX)
(6 . "b") ; block device
(7 . "?") ; multiplexed block device (v7)
(8 . "-") ; regular file
(9 . "n") ; network special file (HP-UX)
(10 . "l") ; symlink
(11 . "?") ; ACL shadow inode (Solaris, not userspace)
(12 . "s") ; socket
(13 . "D") ; door special (Solaris)
(14 . "w")) ; whiteout (BSD)
"A list of file types returned from the `stat' system call.
This is used to map a mode number to a permission string.")
;;;###tramp-autoload
(defun tramp-file-mode-from-int (mode)
"Turn an integer representing a file mode into an ls(1)-like string."
(let ((type (cdr
(assoc (logand (lsh mode -12) 15) tramp-file-mode-type-map)))
(user (logand (lsh mode -6) 7))
(group (logand (lsh mode -3) 7))
(other (logand (lsh mode -0) 7))
(suid (> (logand (lsh mode -9) 4) 0))
(sgid (> (logand (lsh mode -9) 2) 0))
(sticky (> (logand (lsh mode -9) 1) 0)))
(setq user (tramp-file-mode-permissions user suid "s"))
(setq group (tramp-file-mode-permissions group sgid "s"))
(setq other (tramp-file-mode-permissions other sticky "t"))
(concat type user group other)))
(defun tramp-file-mode-permissions (perm suid suid-text)
"Convert a permission bitset into a string.
This is used internally by `tramp-file-mode-from-int'."
(let ((r (> (logand perm 4) 0))
(w (> (logand perm 2) 0))
(x (> (logand perm 1) 0)))
(concat (or (and r "r") "-")
(or (and w "w") "-")
(or (and suid x suid-text) ; suid, execute
(and suid (upcase suid-text)) ; suid, !execute
(and x "x") "-")))) ; !suid
;;;###tramp-autoload
(defun tramp-get-local-uid (id-format)
(if (equal id-format 'integer) (user-uid) (user-login-name)))
;;;###tramp-autoload
(defun tramp-get-local-gid (id-format)
(if (and (fboundp 'group-gid) (equal id-format 'integer))
(tramp-compat-funcall 'group-gid)
(nth 3 (tramp-compat-file-attributes "~/" id-format))))
;;;###tramp-autoload
(defun tramp-check-cached-permissions (vec access)
"Check `file-attributes' caches for VEC.
Return t if according to the cache access type ACCESS is known to
be granted."
(let ((result nil)
(offset (cond
((eq ?r access) 1)
((eq ?w access) 2)
((eq ?x access) 3))))
(dolist (suffix '("string" "integer") result)
(setq
result
(or
result
(let ((file-attr
(tramp-get-file-property
vec (tramp-file-name-localname vec)
(concat "file-attributes-" suffix) nil))
(remote-uid
(tramp-get-connection-property
vec (concat "uid-" suffix) nil))
(remote-gid
(tramp-get-connection-property
vec (concat "gid-" suffix) nil)))
(and
file-attr
(or
;; Not a symlink
(eq t (car file-attr))
(null (car file-attr)))
(or
;; World accessible.
(eq access (aref (nth 8 file-attr) (+ offset 6)))
;; User accessible and owned by user.
(and
(eq access (aref (nth 8 file-attr) offset))
(equal remote-uid (nth 2 file-attr)))
;; Group accessible and owned by user's
;; principal group.
(and
(eq access (aref (nth 8 file-attr) (+ offset 3)))
(equal remote-gid (nth 3 file-attr)))))))))))
;;;###tramp-autoload
(defun tramp-local-host-p (vec)
"Return t if this points to the local host, nil otherwise."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment