summaryrefslogtreecommitdiff
path: root/lisp/net/tramp-cache.el
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2022-10-01 17:17:39 +0200
committerMichael Albinus <michael.albinus@gmx.de>2022-10-01 17:17:39 +0200
commit405466b79c4cc935f98a722d7d7ae9c2cf6eb4b6 (patch)
treee1e713ef5e0bbcde2fef5505a373ae655724a1a1 /lisp/net/tramp-cache.el
parent55f46cc77cb9d72fbabadb63d8aeab45c5e005e2 (diff)
downloademacs-405466b79c4cc935f98a722d7d7ae9c2cf6eb4b6.tar.gz
emacs-405466b79c4cc935f98a722d7d7ae9c2cf6eb4b6.tar.bz2
emacs-405466b79c4cc935f98a722d7d7ae9c2cf6eb4b6.zip
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.
Diffstat (limited to 'lisp/net/tramp-cache.el')
-rw-r--r--lisp/net/tramp-cache.el22
1 files changed, 20 insertions, 2 deletions
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)))