]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-cache.el
Update copyright year to 2015
[gnu-emacs] / lisp / net / tramp-cache.el
index 4c6141fe42bdd6b5421b8c3ec5319fc5cdc8a43e..fb9d5e84c940e4857f52bbe64a9011cd6bff51b0 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tramp-cache.el --- file information caching for Tramp
 
-;; Copyright (C) 2000, 2005-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2005-2015 Free Software Foundation, Inc.
 
 ;; Author: Daniel Pittman <daniel@inanna.danann.net>
 ;;         Michael Albinus <michael.albinus@gmx.de>
 ;;
 ;; - localname is a string.  This are temporary properties, which are
 ;;   related to the file localname is referring to.  Examples:
-;;   "file-exists-p" is t or nile, depending on the file existence, or
+;;   "file-exists-p" is t or nil, depending on the file existence, or
 ;;   "file-attributes" caches the result of the function
-;;  `file-attributes'.
+;;   `file-attributes'.  These entries have a timestamp, and they
+;;   expire after `remote-file-name-inhibit-cache' seconds if this
+;;   variable is set.
 ;;
 ;; - The key is a process.  This are temporary properties related to
 ;;   an open connection.  Examples: "scripts" keeps shell script
@@ -134,7 +136,7 @@ Returns DEFAULT if not set."
                       (tramp-time-diff (current-time) (car value))
                       remote-file-name-inhibit-cache))
                 (and (consp remote-file-name-inhibit-cache)
-                     (tramp-time-less-p
+                     (time-less-p
                       remote-file-name-inhibit-cache (car value)))))
        (setq value (cdr value))
       (setq value default))
@@ -142,7 +144,7 @@ Returns DEFAULT if not set."
     (tramp-message key 8 "%s %s %s" file property value)
     (when (>= tramp-verbose 10)
       (let* ((var (intern (concat "tramp-cache-get-count-" property)))
-            (val (or (ignore-errors (symbol-value var)) 0)))
+            (val (or (and (boundp var) (symbol-value var)) 0)))
        (set var (1+ val))))
     value))
 
@@ -159,14 +161,14 @@ Returns VALUE."
     (tramp-message key 8 "%s %s %s" file property value)
     (when (>= tramp-verbose 10)
       (let* ((var (intern (concat "tramp-cache-set-count-" property)))
-            (val (or (ignore-errors (symbol-value var)) 0)))
+            (val (or (and (boundp var) (symbol-value var)) 0)))
        (set var (1+ val))))
     value))
 
 ;;;###tramp-autoload
 (defun tramp-flush-file-property (key file)
   "Remove all properties of FILE in the cache context of KEY."
-  ;; Remove file property of symlinks.
+  ;; Remove file properties of symlinks.
   (let ((truename (tramp-get-file-property key file "file-truename" nil)))
     (when (and (stringp truename)
               (not (string-equal file truename)))
@@ -181,11 +183,16 @@ Returns VALUE."
 (defun tramp-flush-directory-property (key directory)
   "Remove all properties of DIRECTORY in the cache context of KEY.
 Remove also properties of all files in subdirectories."
-  (let ((directory (tramp-run-real-handler
-                   'directory-file-name (list directory))))
+  (let* ((directory (tramp-run-real-handler
+                   'directory-file-name (list directory)))
+        (truename (tramp-get-file-property key directory "file-truename" nil)))
+    ;; Remove file properties of symlinks.
+    (when (and (stringp truename)
+              (not (string-equal directory truename)))
+      (tramp-flush-directory-property key truename))
     (tramp-message key 8 "%s" directory)
     (maphash
-     (lambda (key value)
+     (lambda (key _value)
        (when (and (stringp (tramp-file-name-localname key))
                  (string-match directory (tramp-file-name-localname key)))
         (remhash key tramp-cache-data)))
@@ -194,15 +201,21 @@ Remove also properties of all files in subdirectories."
 ;; Reverting or killing a buffer should also flush file properties.
 ;; They could have been changed outside Tramp.  In eshell, "ls" would
 ;; not show proper directory contents when a file has been copied or
-;; deleted before.
+;; deleted before.  We must apply `save-match-data', because it would
+;; corrupt other packages otherwise (reported from org).
 (defun tramp-flush-file-function ()
-  "Flush all Tramp cache properties from `buffer-file-name'."
-  (let ((bfn (if (stringp (buffer-file-name))
-                (buffer-file-name)
-              default-directory)))
-    (when (tramp-tramp-file-p bfn)
-      (with-parsed-tramp-file-name bfn nil
-       (tramp-flush-file-property v localname)))))
+  "Flush all Tramp cache properties from `buffer-file-name'.
+This is suppressed for temporary buffers."
+  (save-match-data
+    (unless (or (null (buffer-name))
+               (string-match "^\\( \\|\\*\\)" (buffer-name)))
+      (let ((bfn (if (stringp (buffer-file-name))
+                    (buffer-file-name)
+                  default-directory))
+           (tramp-verbose 0))
+       (when (tramp-tramp-file-p bfn)
+         (with-parsed-tramp-file-name bfn nil
+           (tramp-flush-file-property v localname)))))))
 
 (add-hook 'before-revert-hook 'tramp-flush-file-function)
 (add-hook 'eshell-pre-command-hook 'tramp-flush-file-function)
@@ -271,7 +284,7 @@ KEY identifies the connection, it is either a process or a vector."
    (let ((hash (gethash key tramp-cache-data))
         properties)
      (when (hash-table-p hash)
-       (maphash (lambda (x y) (add-to-list 'properties x 'append)) hash))
+       (maphash (lambda (x _y) (add-to-list 'properties x 'append)) hash))
      properties))
   (setq tramp-cache-data-changed t)
   (remhash key tramp-cache-data))
@@ -283,6 +296,21 @@ KEY identifies the connection, it is either a process or a vector."
     (let (result)
       (maphash
        (lambda (key value)
+        ;; Remove text properties from KEY and VALUE.
+        ;; `substring-no-properties' does not exist in XEmacs.
+        (when (functionp 'substring-no-properties)
+          (when (vectorp key)
+            (dotimes (i (length key))
+              (when (stringp (aref key i))
+                (aset key i
+                      (tramp-compat-funcall
+                       'substring-no-properties (aref key i))))))
+          (when (stringp key)
+            (setq key (tramp-compat-funcall 'substring-no-properties key)))
+          (when (stringp value)
+            (setq value
+                  (tramp-compat-funcall 'substring-no-properties value))))
+        ;; Dump.
         (let ((tmp (format
                     "(%s %s)"
                     (if (processp key)
@@ -302,7 +330,7 @@ KEY identifies the connection, it is either a process or a vector."
   "Return a list of all known connection vectors according to `tramp-cache'."
     (let (result)
       (maphash
-       (lambda (key value)
+       (lambda (key _value)
         (when (and (vectorp key) (null (aref key 3)))
           (add-to-list 'result key)))
        tramp-cache-data)
@@ -366,7 +394,7 @@ This function is added always in `tramp-get-completion-function'
 for all methods.  Resulting data are derived from connection history."
   (let (res)
     (maphash
-     (lambda (key value)
+     (lambda (key _value)
        (if (and (vectorp key)
                (string-equal method (tramp-file-name-method key))
                (not (tramp-file-name-localname key)))
@@ -388,6 +416,7 @@ for all methods.  Resulting data are derived from connection history."
       (with-temp-buffer
        (insert-file-contents tramp-persistency-file-name)
        (let ((list (read (current-buffer)))
+             (tramp-verbose 0)
              element key item)
          (while (setq element (pop list))
            (setq key (pop element))