--- lisp/ChangeLog | 6 +++++ lisp/tramp.el | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d52781c..60a83df 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2009-08-14 Julian Scheid <[email protected]> + + * tramp.el (tramp-handle-file-readable-p): Examine file-attributes + cache to see if request can be satisfied without remote operation. + (tramp-handle-file-writable-p): Likewise. + 2009-08-14 Michael Albinus <[email protected]> * tramp.el (tramp-message-show-message): New defvar. diff --git a/lisp/tramp.el b/lisp/tramp.el index 1ecae2c..c75a6c8 100644 --- a/lisp/tramp.el +++ b/lisp/tramp.el @@ -2844,7 +2844,37 @@ and gid of the corresponding user is taken. Both parameters must be integers." "Like `file-readable-p' for Tramp files." (with-parsed-tramp-file-name filename nil (with-file-property v localname "file-readable-p" - (zerop (tramp-run-test "-r" filename))))) + (or (let ((result nil)) + (dolist (suffix '("string" "integer") result) + (setq + result + (or + result + (let ((file-attr + (tramp-get-file-property + v localname + (concat "file-attributes-" suffix) nil)) + (remote-uid + (tramp-get-connection-property + v (concat "uid-" suffix) nil)) + (remote-gid + (tramp-get-connection-property + v (concat "gid-" suffix) nil))) + (and + file-attr + (or + ;; World readable + (eq ?r (aref (nth 8 file-attr) 7)) + ;; User readable and owned by user + (and + (eq ?r (aref (nth 8 file-attr) 1)) + (eq remote-uid (nth 2 file-attr))) + ;; Group readable and owned by user's + ;; principal group + (and + (eq ?r (aref (nth 8 file-attr) 4)) + (eq remote-gid (nth 3 file-attr)))))))))) + (zerop (tramp-run-test "-r" filename)))))) ;; When the remote shell is started, it looks for a shell which groks ;; tilde expansion. Here, we assume that all shells which grok tilde @@ -2934,8 +2964,37 @@ value of `default-file-modes', without execute permissions." (with-parsed-tramp-file-name filename nil (with-file-property v localname "file-writable-p" (if (file-exists-p filename) - ;; Existing files must be writable. - (zerop (tramp-run-test "-w" filename)) + (or (let ((result nil)) + (dolist (suffix '("string" "integer") result) + (setq + result + (or + result + (let ((file-attr + (tramp-get-file-property + v localname + (concat "file-attributes-" suffix) nil)) + (remote-uid + (tramp-get-connection-property + v (concat "uid-" suffix) nil)) + (remote-gid + (tramp-get-connection-property + v (concat "gid-" suffix) nil))) + (and + file-attr + (or + ;; World writable + (eq ?w (aref (nth 8 file-attr) 8)) + ;; User writable and owned by user + (and + (eq ?w (aref (nth 8 file-attr) 2)) + (eq remote-uid (nth 2 file-attr))) + ;; Group writable and owned by user's + ;; principal group + (and + (eq ?w (aref (nth 8 file-attr) 5)) + (eq remote-gid (nth 3 file-attr)))))))))) + (zerop (tramp-run-test "-w" filename))) ;; If file doesn't exist, check if directory is writable. (and (zerop (tramp-run-test "-d" (file-name-directory filename))) -- 1.6.4 _______________________________________________ Tramp-devel mailing list [email protected] http://lists.gnu.org/mailman/listinfo/tramp-devel
