From: Michael Albinus Date: Sat, 1 Oct 2022 15:17:39 +0000 (+0200) Subject: Use a version for the Tramp cache X-Git-Tag: emacs-29.0.90~1856^2~97 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=405466b79c4cc935f98a722d7d7ae9c2cf6eb4b6;p=emacs.git 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 . * lisp/net/tramp-cmds.el (tramp-cleanup-all-connections): Re-initialize the cache version. --- diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index d8f31daa1fa..4d7d35a4de6 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 d36514bab26..0442fa74096 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