;;; tramp-cache.el --- file information caching for Tramp
-;; Copyright (C) 2000, 2005-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2005-2016 Free Software Foundation, Inc.
;; Author: Daniel Pittman <daniel@inanna.danann.net>
;; Michael Albinus <michael.albinus@gmx.de>
Every entry has the form (REGEXP PROPERTY VALUE). The regexp
matches remote file names. It can be nil. PROPERTY is a string,
and VALUE the corresponding value. They are used, if there is no
-matching entry for PROPERTY in `tramp-cache-data'."
+matching entry for PROPERTY in `tramp-cache-data'. For more
+details see the info pages."
:group 'tramp
:version "24.4"
:type '(repeat (list (choice :tag "File Name regexp" regexp (const nil))
(choice :tag " Value" sexp))))
(defcustom tramp-persistency-file-name
- (cond
- ;; GNU Emacs.
- ((and (fboundp 'locate-user-emacs-file))
- (expand-file-name (tramp-compat-funcall 'locate-user-emacs-file "tramp")))
- ((and (boundp 'user-emacs-directory)
- (stringp (symbol-value 'user-emacs-directory))
- (file-directory-p (symbol-value 'user-emacs-directory)))
- (expand-file-name "tramp" (symbol-value 'user-emacs-directory)))
- ((and (not (featurep 'xemacs)) (file-directory-p "~/.emacs.d/"))
- "~/.emacs.d/tramp")
- ;; XEmacs.
- ((and (boundp 'user-init-directory)
- (stringp (symbol-value 'user-init-directory))
- (file-directory-p (symbol-value 'user-init-directory)))
- (expand-file-name "tramp" (symbol-value 'user-init-directory)))
- ((and (featurep 'xemacs) (file-directory-p "~/.xemacs/"))
- "~/.xemacs/tramp")
- ;; For users without `~/.emacs.d/' or `~/.xemacs/'.
- (t "~/.tramp"))
+ (expand-file-name (locate-user-emacs-file "tramp"))
"File which keeps connection history for Tramp connections."
:group 'tramp
:type 'file)
(defun tramp-get-file-property (key file property default)
"Get the PROPERTY of FILE from the cache context of KEY.
Returns DEFAULT if not set."
- ;; Unify localname.
+ ;; Unify localname. Remove hop from vector.
(setq key (copy-sequence key))
(aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
+ (aset key 4 nil)
(let* ((hash (tramp-get-hash-table key))
(value (when (hash-table-p hash) (gethash property hash))))
(if
(defun tramp-set-file-property (key file property value)
"Set the PROPERTY of FILE to VALUE, in the cache context of KEY.
Returns VALUE."
- ;; Unify localname.
+ ;; Unify localname. Remove hop from vector.
(setq key (copy-sequence key))
(aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
+ (aset key 4 nil)
(let ((hash (tramp-get-hash-table key)))
;; We put the timestamp there.
(puthash property (cons (current-time) value) hash)
;;;###tramp-autoload
(defun tramp-flush-file-property (key file)
"Remove all properties of FILE in the cache context of KEY."
- ;; Remove file properties of symlinks.
- (let ((truename (tramp-get-file-property key file "file-truename" nil)))
+ (let* ((file (tramp-run-real-handler
+ 'directory-file-name (list file)))
+ (truename (tramp-get-file-property key file "file-truename" nil)))
+ ;; Remove file properties of symlinks.
(when (and (stringp truename)
- (not (string-equal file truename)))
- (tramp-flush-file-property key truename)))
- ;; Unify localname.
- (setq key (copy-sequence key))
- (aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
- (tramp-message key 8 "%s" file)
- (remhash key tramp-cache-data))
+ (not (string-equal file (directory-file-name truename))))
+ (tramp-flush-file-property key truename))
+ ;; Unify localname. Remove hop from vector.
+ (setq key (copy-sequence key))
+ (aset key 3 file)
+ (aset key 4 nil)
+ (tramp-message key 8 "%s" file)
+ (remhash key tramp-cache-data)))
;;;###tramp-autoload
(defun tramp-flush-directory-property (key 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)))
+ (not (string-equal directory (directory-file-name truename))))
(tramp-flush-directory-property key truename))
(tramp-message key 8 "%s" directory)
(maphash
(lambda (key _value)
(when (and (stringp (tramp-file-name-localname key))
- (string-match directory (tramp-file-name-localname key)))
+ (string-match (regexp-quote directory)
+ (tramp-file-name-localname key)))
(remhash key tramp-cache-data)))
tramp-cache-data)))
"Get the named PROPERTY for the connection.
KEY identifies the connection, it is either a process or a vector.
If the value is not set for the connection, returns DEFAULT."
- ;; Unify key by removing localname from vector. Work with a copy in
- ;; order to avoid side effects.
+ ;; Unify key by removing localname and hop from vector. Work with a
+ ;; copy in order to avoid side effects.
(when (vectorp key)
(setq key (copy-sequence key))
- (aset key 3 nil))
+ (aset key 3 nil)
+ (aset key 4 nil))
(let* ((hash (tramp-get-hash-table key))
(value (if (hash-table-p hash)
(gethash property hash default)
"Set the named PROPERTY of a connection to VALUE.
KEY identifies the connection, it is either a process or a vector.
PROPERTY is set persistent when KEY is a vector."
- ;; Unify key by removing localname from vector. Work with a copy in
- ;; order to avoid side effects.
+ ;; Unify key by removing localname and hop from vector. Work with a
+ ;; copy in order to avoid side effects.
(when (vectorp key)
(setq key (copy-sequence key))
- (aset key 3 nil))
+ (aset key 3 nil)
+ (aset key 4 nil))
(let ((hash (tramp-get-hash-table key)))
(puthash property value hash)
(setq tramp-cache-data-changed t)
(defun tramp-flush-connection-property (key)
"Remove all properties identified by KEY.
KEY identifies the connection, it is either a process or a vector."
- ;; Unify key by removing localname from vector. Work with a copy in
- ;; order to avoid side effects.
+ ;; Unify key by removing localname and hop from vector. Work with a
+ ;; copy in order to avoid side effects.
(when (vectorp key)
(setq key (copy-sequence key))
- (aset key 3 nil))
+ (aset key 3 nil)
+ (aset key 4 nil))
(tramp-message
key 7 "%s %s" key
(let ((hash (gethash key tramp-cache-data))
(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))))
+ (when (vectorp key)
+ (dotimes (i (length key))
+ (when (stringp (aref key i))
+ (aset key i (substring-no-properties (aref key i))))))
+ (when (stringp key)
+ (setq key (substring-no-properties key)))
+ (when (stringp value)
+ (setq value (substring-no-properties value)))
;; Dump.
(let ((tmp (format
"(%s %s)"
;; When "emacs -Q" has been called, both variables are nil.
;; We do not load the persistency file then, in order to
;; have a clean test environment.
- (or (and (boundp 'init-file-user) (symbol-value 'init-file-user))
- (and (boundp 'site-run-file) (symbol-value 'site-run-file))))
+ (or init-file-user
+ site-run-file))
(condition-case err
(with-temp-buffer
(insert-file-contents tramp-persistency-file-name)
(clrhash tramp-cache-data))
(error
;; File is corrupted.
- (message "Tramp persistency file '%s' is corrupted: %s"
+ (message "Tramp persistency file `%s' is corrupted: %s"
tramp-persistency-file-name (error-message-string err))
(clrhash tramp-cache-data))))