diff options
| author | Michael Albinus | 2022-09-11 14:53:14 +0200 |
|---|---|---|
| committer | Michael Albinus | 2022-09-11 14:53:14 +0200 |
| commit | cba83d989359d667e52dad4e0e9eadf6f77cc38f (patch) | |
| tree | e21e822010ca2459725a915c996e9a0bcb724777 | |
| parent | f47a5324f44e5b8d0016cff2a4f995ff418a5d19 (diff) | |
| download | emacs-cba83d989359d667e52dad4e0e9eadf6f77cc38f.tar.gz emacs-cba83d989359d667e52dad4e0e9eadf6f77cc38f.zip | |
Disable Tramp cache for relative file names
* lisp/net/tramp.el (tramp-file-name-unify):
Return `tramp-cache-undefined' if LOCALNAME is a relative file name.
* lisp/net/tramp-cache.el (tramp-get-file-property)
(tramp-set-file-property, tramp-file-property-p)
(tramp-flush-file-property, tramp-flush-file-upper-properties)
(tramp-flush-file-properties): Handle KEY being
`tramp-cache-undefined'.
(tramp-flush-file-function): Revert last change.
| -rw-r--r-- | lisp/net/tramp-cache.el | 159 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 28 |
2 files changed, 97 insertions, 90 deletions
diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index 93bcdf4b973..58954c238e0 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el | |||
| @@ -28,7 +28,7 @@ | |||
| 28 | ;; An implementation of information caching for remote files. | 28 | ;; An implementation of information caching for remote files. |
| 29 | 29 | ||
| 30 | ;; Each connection, identified by a `tramp-file-name' structure or by | 30 | ;; Each connection, identified by a `tramp-file-name' structure or by |
| 31 | ;; a process, has a unique cache. We distinguish 4 kind of caches, | 31 | ;; a process, has a unique cache. We distinguish 5 kind of caches, |
| 32 | ;; depending on the key: | 32 | ;; depending on the key: |
| 33 | ;; | 33 | ;; |
| 34 | ;; - localname is nil. These are reusable properties. Examples: | 34 | ;; - localname is nil. These are reusable properties. Examples: |
| @@ -37,13 +37,14 @@ | |||
| 37 | ;; host when starting a Perl script. These properties are saved in | 37 | ;; host when starting a Perl script. These properties are saved in |
| 38 | ;; the file `tramp-persistency-file-name'. | 38 | ;; the file `tramp-persistency-file-name'. |
| 39 | ;; | 39 | ;; |
| 40 | ;; - localname is a string. These are temporary properties, which are | 40 | ;; - localname is an absolute file name. These are temporary |
| 41 | ;; related to the file localname is referring to. Examples: | 41 | ;; properties, which are related to the file localname is referring |
| 42 | ;; "file-exists-p" is t or nil, depending on the file existence, or | 42 | ;; to. Examples: "file-exists-p" is t or nil, depending on the file |
| 43 | ;; "file-attributes" caches the result of the function | 43 | ;; existence, or "file-attributes" caches the result of the function |
| 44 | ;; `file-attributes'. These entries have a timestamp, and they | 44 | ;; `file-attributes'. These entries have a timestamp, and they |
| 45 | ;; expire after `remote-file-name-inhibit-cache' seconds if this | 45 | ;; expire after `remote-file-name-inhibit-cache' seconds if this |
| 46 | ;; variable is set. | 46 | ;; variable is set. These properties are taken into account only if |
| 47 | ;; the connection is established, or `non-essential' is nil. | ||
| 47 | ;; | 48 | ;; |
| 48 | ;; - The key is a process. These are temporary properties related to | 49 | ;; - The key is a process. These are temporary properties related to |
| 49 | ;; an open connection. Examples: "scripts" keeps shell script | 50 | ;; an open connection. Examples: "scripts" keeps shell script |
| @@ -135,39 +136,41 @@ If KEY is `tramp-cache-undefined', don't create anything, and return nil." | |||
| 135 | Return DEFAULT if not set." | 136 | Return DEFAULT if not set." |
| 136 | ;; Unify localname. Remove hop from `tramp-file-name' structure. | 137 | ;; Unify localname. Remove hop from `tramp-file-name' structure. |
| 137 | (setq key (tramp-file-name-unify key file)) | 138 | (setq key (tramp-file-name-unify key file)) |
| 138 | (let* ((hash (tramp-get-hash-table key)) | 139 | (if (eq key tramp-cache-undefined) default |
| 139 | (cached (and (hash-table-p hash) (gethash property hash))) | 140 | (let* ((hash (tramp-get-hash-table key)) |
| 140 | (cached-at (and (consp cached) (format-time-string "%T" (car cached)))) | 141 | (cached (and (hash-table-p hash) (gethash property hash))) |
| 141 | (value default) | 142 | (cached-at |
| 142 | cache-used) | 143 | (and (consp cached) (format-time-string "%T" (car cached)))) |
| 143 | 144 | (value default) | |
| 144 | (when ;; We take the value only if there is any, and | 145 | cache-used) |
| 145 | ;; `remote-file-name-inhibit-cache' indicates that it is | 146 | |
| 146 | ;; still valid. Otherwise, DEFAULT is set. | 147 | (when ;; We take the value only if there is any, and |
| 147 | (and (consp cached) | 148 | ;; `remote-file-name-inhibit-cache' indicates that it is |
| 148 | (or (null remote-file-name-inhibit-cache) | 149 | ;; still valid. Otherwise, DEFAULT is set. |
| 149 | (and (integerp remote-file-name-inhibit-cache) | 150 | (and (consp cached) |
| 150 | (time-less-p | 151 | (or (null remote-file-name-inhibit-cache) |
| 151 | nil | 152 | (and (integerp remote-file-name-inhibit-cache) |
| 152 | (time-add (car cached) remote-file-name-inhibit-cache))) | 153 | (time-less-p |
| 153 | (and (consp remote-file-name-inhibit-cache) | 154 | nil |
| 154 | (time-less-p | 155 | (time-add (car cached) remote-file-name-inhibit-cache))) |
| 155 | remote-file-name-inhibit-cache (car cached))))) | 156 | (and (consp remote-file-name-inhibit-cache) |
| 156 | (setq value (cdr cached) | 157 | (time-less-p |
| 157 | cache-used t)) | 158 | remote-file-name-inhibit-cache (car cached))))) |
| 158 | 159 | (setq value (cdr cached) | |
| 159 | (tramp-message | 160 | cache-used t)) |
| 160 | key 8 "%s %s %s; inhibit: %s; cache used: %s; cached at: %s" | 161 | |
| 161 | (tramp-file-name-localname key) | 162 | (tramp-message |
| 162 | property value remote-file-name-inhibit-cache cache-used cached-at) | 163 | key 8 "%s %s %s; inhibit: %s; cache used: %s; cached at: %s" |
| 163 | ;; For analysis purposes, count the number of getting this file attribute. | 164 | (tramp-file-name-localname key) |
| 164 | (when (>= tramp-verbose 10) | 165 | property value remote-file-name-inhibit-cache cache-used cached-at) |
| 165 | (let* ((var (intern (concat "tramp-cache-get-count-" property))) | 166 | ;; For analysis purposes, count the number of getting this file attribute. |
| 166 | (val (or (and (boundp var) (numberp (symbol-value var)) | 167 | (when (>= tramp-verbose 10) |
| 167 | (symbol-value var)) | 168 | (let* ((var (intern (concat "tramp-cache-get-count-" property))) |
| 168 | 0))) | 169 | (val (or (and (boundp var) (numberp (symbol-value var)) |
| 169 | (set var (1+ val)))) | 170 | (symbol-value var)) |
| 170 | value)) | 171 | 0))) |
| 172 | (set var (1+ val)))) | ||
| 173 | value))) | ||
| 171 | 174 | ||
| 172 | (add-hook 'tramp-cache-unload-hook | 175 | (add-hook 'tramp-cache-unload-hook |
| 173 | (lambda () | 176 | (lambda () |
| @@ -180,19 +183,20 @@ Return DEFAULT if not set." | |||
| 180 | Return VALUE." | 183 | Return VALUE." |
| 181 | ;; Unify localname. Remove hop from `tramp-file-name' structure. | 184 | ;; Unify localname. Remove hop from `tramp-file-name' structure. |
| 182 | (setq key (tramp-file-name-unify key file)) | 185 | (setq key (tramp-file-name-unify key file)) |
| 183 | (let ((hash (tramp-get-hash-table key))) | 186 | (if (eq key tramp-cache-undefined) value |
| 184 | ;; We put the timestamp there. | 187 | (let ((hash (tramp-get-hash-table key))) |
| 185 | (puthash property (cons (current-time) value) hash) | 188 | ;; We put the timestamp there. |
| 186 | (tramp-message | 189 | (puthash property (cons (current-time) value) hash) |
| 187 | key 8 "%s %s %s" (tramp-file-name-localname key) property value) | 190 | (tramp-message |
| 188 | ;; For analysis purposes, count the number of setting this file attribute. | 191 | key 8 "%s %s %s" (tramp-file-name-localname key) property value) |
| 189 | (when (>= tramp-verbose 10) | 192 | ;; For analysis purposes, count the number of setting this file attribute. |
| 190 | (let* ((var (intern (concat "tramp-cache-set-count-" property))) | 193 | (when (>= tramp-verbose 10) |
| 191 | (val (or (and (boundp var) (numberp (symbol-value var)) | 194 | (let* ((var (intern (concat "tramp-cache-set-count-" property))) |
| 192 | (symbol-value var)) | 195 | (val (or (and (boundp var) (numberp (symbol-value var)) |
| 193 | 0))) | 196 | (symbol-value var)) |
| 194 | (set var (1+ val)))) | 197 | 0))) |
| 195 | value)) | 198 | (set var (1+ val)))) |
| 199 | value))) | ||
| 196 | 200 | ||
| 197 | (add-hook 'tramp-cache-unload-hook | 201 | (add-hook 'tramp-cache-unload-hook |
| 198 | (lambda () | 202 | (lambda () |
| @@ -202,19 +206,22 @@ Return VALUE." | |||
| 202 | ;;;###tramp-autoload | 206 | ;;;###tramp-autoload |
| 203 | (defun tramp-file-property-p (key file property) | 207 | (defun tramp-file-property-p (key file property) |
| 204 | "Check whether PROPERTY of FILE is defined in the cache context of KEY." | 208 | "Check whether PROPERTY of FILE is defined in the cache context of KEY." |
| 205 | (not (eq (tramp-get-file-property key file property tramp-cache-undefined) | 209 | (and |
| 206 | tramp-cache-undefined))) | 210 | (not (eq key tramp-cache-undefined)) |
| 211 | (not (eq (tramp-get-file-property key file property tramp-cache-undefined) | ||
| 212 | tramp-cache-undefined)))) | ||
| 207 | 213 | ||
| 208 | ;;;###tramp-autoload | 214 | ;;;###tramp-autoload |
| 209 | (defun tramp-flush-file-property (key file property) | 215 | (defun tramp-flush-file-property (key file property) |
| 210 | "Remove PROPERTY of FILE in the cache context of KEY." | 216 | "Remove PROPERTY of FILE in the cache context of KEY." |
| 211 | ;; Unify localname. Remove hop from `tramp-file-name' structure. | 217 | ;; Unify localname. Remove hop from `tramp-file-name' structure. |
| 212 | (setq key (tramp-file-name-unify key file)) | 218 | (setq key (tramp-file-name-unify key file)) |
| 213 | (remhash property (tramp-get-hash-table key)) | 219 | (unless (eq key tramp-cache-undefined) |
| 214 | (tramp-message key 8 "%s %s" (tramp-file-name-localname key) property) | 220 | (remhash property (tramp-get-hash-table key)) |
| 215 | (when (>= tramp-verbose 10) | 221 | (tramp-message key 8 "%s %s" (tramp-file-name-localname key) property) |
| 216 | (let ((var (intern (concat "tramp-cache-set-count-" property)))) | 222 | (when (>= tramp-verbose 10) |
| 217 | (makunbound var)))) | 223 | (let ((var (intern (concat "tramp-cache-set-count-" property)))) |
| 224 | (makunbound var))))) | ||
| 218 | 225 | ||
| 219 | (defun tramp-flush-file-upper-properties (key file) | 226 | (defun tramp-flush-file-upper-properties (key file) |
| 220 | "Remove some properties of FILE's upper directory." | 227 | "Remove some properties of FILE's upper directory." |
| @@ -224,12 +231,14 @@ Return VALUE." | |||
| 224 | (file (directory-file-name file))) | 231 | (file (directory-file-name file))) |
| 225 | ;; Unify localname. Remove hop from `tramp-file-name' structure. | 232 | ;; Unify localname. Remove hop from `tramp-file-name' structure. |
| 226 | (setq key (tramp-file-name-unify key file)) | 233 | (setq key (tramp-file-name-unify key file)) |
| 227 | (dolist (property (hash-table-keys (tramp-get-hash-table key))) | 234 | (unless (eq key tramp-cache-undefined) |
| 228 | (when (string-match-p | 235 | (dolist (property (hash-table-keys (tramp-get-hash-table key))) |
| 229 | (rx | 236 | (when (string-match-p |
| 230 | bos (| "directory-" "file-name-all-completions" "file-entries")) | 237 | (rx |
| 231 | property) | 238 | bos (| "directory-" "file-name-all-completions" |
| 232 | (tramp-flush-file-property key file property)))))) | 239 | "file-entries")) |
| 240 | property) | ||
| 241 | (tramp-flush-file-property key file property))))))) | ||
| 233 | 242 | ||
| 234 | ;;;###tramp-autoload | 243 | ;;;###tramp-autoload |
| 235 | (defun tramp-flush-file-properties (key file) | 244 | (defun tramp-flush-file-properties (key file) |
| @@ -237,14 +246,15 @@ Return VALUE." | |||
| 237 | (let ((truename (tramp-get-file-property key file "file-truename"))) | 246 | (let ((truename (tramp-get-file-property key file "file-truename"))) |
| 238 | ;; Unify localname. Remove hop from `tramp-file-name' structure. | 247 | ;; Unify localname. Remove hop from `tramp-file-name' structure. |
| 239 | (setq key (tramp-file-name-unify key file)) | 248 | (setq key (tramp-file-name-unify key file)) |
| 240 | (tramp-message key 8 "%s" (tramp-file-name-localname key)) | 249 | (unless (eq key tramp-cache-undefined) |
| 241 | (remhash key tramp-cache-data) | 250 | (tramp-message key 8 "%s" (tramp-file-name-localname key)) |
| 242 | ;; Remove file properties of symlinks. | 251 | (remhash key tramp-cache-data) |
| 243 | (when (and (stringp truename) | 252 | ;; Remove file properties of symlinks. |
| 244 | (not (string-equal file (directory-file-name truename)))) | 253 | (when (and (stringp truename) |
| 245 | (tramp-flush-file-properties key truename)) | 254 | (not (string-equal file (directory-file-name truename)))) |
| 246 | ;; Remove selected properties of upper directory. | 255 | (tramp-flush-file-properties key truename)) |
| 247 | (tramp-flush-file-upper-properties key file))) | 256 | ;; Remove selected properties of upper directory. |
| 257 | (tramp-flush-file-upper-properties key file)))) | ||
| 248 | 258 | ||
| 249 | ;;;###tramp-autoload | 259 | ;;;###tramp-autoload |
| 250 | (defun tramp-flush-directory-properties (key directory) | 260 | (defun tramp-flush-directory-properties (key directory) |
| @@ -285,8 +295,7 @@ This is suppressed for temporary buffers." | |||
| 285 | (tramp-verbose 0)) | 295 | (tramp-verbose 0)) |
| 286 | (when (tramp-tramp-file-p bfn) | 296 | (when (tramp-tramp-file-p bfn) |
| 287 | (tramp-flush-file-properties | 297 | (tramp-flush-file-properties |
| 288 | (tramp-dissect-file-name bfn) | 298 | (tramp-dissect-file-name bfn) (tramp-file-local-name bfn))))))) |
| 289 | (tramp-file-local-name (expand-file-name bfn)))))))) | ||
| 290 | 299 | ||
| 291 | (add-hook 'before-revert-hook #'tramp-flush-file-function) | 300 | (add-hook 'before-revert-hook #'tramp-flush-file-function) |
| 292 | (add-hook 'eshell-pre-command-hook #'tramp-flush-file-function) | 301 | (add-hook 'eshell-pre-command-hook #'tramp-flush-file-function) |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 15380ed94dd..90cc03c188e 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -1504,23 +1504,21 @@ If nil, return `tramp-default-port'." | |||
| 1504 | ;;;###tramp-autoload | 1504 | ;;;###tramp-autoload |
| 1505 | (defun tramp-file-name-unify (vec &optional localname) | 1505 | (defun tramp-file-name-unify (vec &optional localname) |
| 1506 | "Unify VEC by removing localname and hop from `tramp-file-name' structure. | 1506 | "Unify VEC by removing localname and hop from `tramp-file-name' structure. |
| 1507 | If LOCALNAME is a string, set it as localname. | 1507 | If LOCALNAME is an absolute file name, set it as localname. If |
| 1508 | LOCALNAME is a relative file name, return `tramp-cache-undefined'. | ||
| 1508 | Objects returned by this function compare `equal' if they refer to the | 1509 | Objects returned by this function compare `equal' if they refer to the |
| 1509 | same connection. Make a copy in order to avoid side effects." | 1510 | same connection. Make a copy in order to avoid side effects." |
| 1510 | (when (tramp-file-name-p vec) | 1511 | (if (and (stringp localname) |
| 1511 | (setq vec (copy-tramp-file-name vec)) | 1512 | (not (file-name-absolute-p localname))) |
| 1512 | (setf (tramp-file-name-localname vec) | 1513 | (setq vec tramp-cache-undefined) |
| 1513 | (and (stringp localname) | 1514 | (when (tramp-file-name-p vec) |
| 1514 | ;; FIXME: This is a sanity check. When this error | 1515 | (setq vec (copy-tramp-file-name vec)) |
| 1515 | ;; doesn't happen for a while, it can be removed. | 1516 | (setf (tramp-file-name-localname vec) |
| 1516 | (or (file-name-absolute-p localname) | 1517 | (and (stringp localname) |
| 1517 | (tramp-error | 1518 | (tramp-compat-file-name-unquote |
| 1518 | vec 'file-error | 1519 | (directory-file-name localname))) |
| 1519 | "File `%s' must be absolute, please report a bug!" | 1520 | (tramp-file-name-hop vec) nil)) |
| 1520 | localname)) | 1521 | vec)) |
| 1521 | (tramp-compat-file-name-unquote (directory-file-name localname))) | ||
| 1522 | (tramp-file-name-hop vec) nil)) | ||
| 1523 | vec) | ||
| 1524 | 1522 | ||
| 1525 | (put #'tramp-file-name-unify 'tramp-suppress-trace t) | 1523 | (put #'tramp-file-name-unify 'tramp-suppress-trace t) |
| 1526 | 1524 | ||