tramp-devel
[Top][All Lists]
Advanced

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

[PATCH 1/1] * tramp.el (tramp-handle-file-readable-p): Examine file-attr


From: Julian Scheid
Subject: [PATCH 1/1] * 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.
Date: Sat, 15 Aug 2009 21:23:47 +1200

---
 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  <address@hidden>
+
+       * 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  <address@hidden>
 
        * 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





reply via email to

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