emacs-diffs
[Top][All Lists]
Advanced

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

master 405466b79c: Use a version for the Tramp cache


From: Michael Albinus
Subject: master 405466b79c: Use a version for the Tramp cache
Date: Sat, 1 Oct 2022 11:17:51 -0400 (EDT)

branch: master
commit 405466b79c4cc935f98a722d7d7ae9c2cf6eb4b6
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Use a version for the Tramp cache
    
    * lisp/net/tramp-cache.el (tramp-cache-version): New defconst.
    (top): Check the cache version, and flush the cache in case of
    mismatch.  Suggested by Paul Pogonyshev <pogonyshev@gmail.com>.
    
    * lisp/net/tramp-cmds.el (tramp-cleanup-all-connections):
    Re-initialize the cache version.
---
 lisp/net/tramp-cache.el | 22 ++++++++++++++++++++--
 lisp/net/tramp-cmds.el  |  4 ++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el
index d8f31daa1f..4d7d35a4de 100644
--- a/lisp/net/tramp-cache.el
+++ b/lisp/net/tramp-cache.el
@@ -28,7 +28,7 @@
 ;; An implementation of information caching for remote files.
 
 ;; Each connection, identified by a `tramp-file-name' structure or by
-;; a process, has a unique cache.  We distinguish 5 kind of caches,
+;; a process, has a unique cache.  We distinguish 6 kind of caches,
 ;; depending on the key:
 ;;
 ;; - localname is nil.  These are reusable properties.  Examples:
@@ -56,6 +56,10 @@
 ;;   "{uid,gid}-{integer,string}" are the local uid and gid, and
 ;;   "locale" is the used shell locale.
 ;;
+;; - The key is `tramp-cache-version'.  It keeps the Tramp version the
+;;   cache data was produced with.  If the cache is read by another
+;;   Tramp version, it is flushed.
+;;
 ;; - The key is `tramp-cache-undefined'.  All functions return the
 ;;   expected values, but nothing is cached.
 
@@ -105,6 +109,10 @@ details see the info pages."
   :group 'tramp
   :type 'file)
 
+;;;###tramp-autoload
+(defconst tramp-cache-version (make-tramp-file-name :method "cache")
+"Virtual connection vector for Tramp version.")
+
 (defvar tramp-cache-data-changed nil
   "Whether persistent cache data have been changed.")
 
@@ -632,9 +640,16 @@ for all methods.  Resulting data are derived from 
connection history."
                ;; initialized properly by side effect.
                (unless (tramp-connection-property-p key (car item))
                  (tramp-set-connection-property key (pop item) (car item)))))))
+       ;; Check Tramp version.  Clear cache in case of mismatch.
+       (unless (string-equal
+                (tramp-get-connection-property
+                 tramp-cache-version "tramp-version" "")
+                tramp-version)
+         (signal 'file-error nil))
        (setq tramp-cache-data-changed nil))
     (file-error
-     ;; Most likely because the file doesn't exist yet.  No message.
+     ;; Most likely because the file doesn't exist yet, or the Tramp
+     ;; version doesn't match.  No message.
      (clrhash tramp-cache-data))
     (error
      ;; File is corrupted.
@@ -642,6 +657,9 @@ for all methods.  Resulting data are derived from 
connection history."
              tramp-persistency-file-name (error-message-string err))
      (clrhash tramp-cache-data))))
 
+;; Initialize the cache version.
+(tramp-set-connection-property tramp-cache-version "tramp-version" 
tramp-version)
+
 (add-hook 'tramp-unload-hook
          (lambda ()
            (unload-feature 'tramp-cache 'force)))
diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el
index d36514bab2..0442fa7409 100644
--- a/lisp/net/tramp-cmds.el
+++ b/lisp/net/tramp-cmds.el
@@ -179,6 +179,10 @@ This includes password cache, file cache, connection 
cache, buffers."
   ;; Flush file and connection cache.
   (clrhash tramp-cache-data)
 
+  ;; Initialize the cache version.
+  (tramp-set-connection-property
+   tramp-cache-version "tramp-version" tramp-version)
+
   ;; Remove ad-hoc proxies.
   (let ((proxies tramp-default-proxies-alist))
     (while proxies



reply via email to

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