From 7c3404ecc23078efc7438243701a9dfc5da0e5b1 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Mon, 1 Dec 2008 06:37:54 +0000 Subject: [PATCH] * net/tramp-cache.el (tramp-cache-data-changed): New defvar. (tramp-set-connection-property, tramp-flush-connection-property) (tramp-dump-connection-properties): Use it. --- lisp/ChangeLog | 6 ++++ lisp/net/tramp-cache.el | 75 ++++++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e22d1d8c475..efb33f53d3f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2008-12-01 Michael Albinus + + * net/tramp-cache.el (tramp-cache-data-changed): New defvar. + (tramp-set-connection-property, tramp-flush-connection-property) + (tramp-dump-connection-properties): Use it. + 2008-11-30 Chong Yidong * wdired.el (wdired-finish-edit): If displaying a single file, diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index e4218808574..466cd7f5a41 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -89,6 +89,9 @@ :group 'tramp :type 'file) +(defvar tramp-cache-data-changed nil + "Whether persistent cache data have been changed.") + (defun tramp-get-file-property (vec file property default) "Get the PROPERTY of FILE from the cache context of VEC. Returns DEFAULT if not set." @@ -195,6 +198,7 @@ PROPERTY is set persistent when KEY is a vector." (puthash key (make-hash-table :test 'equal) tramp-cache-data)))) (puthash property value hash) + (setq tramp-cache-data-changed t) ;; This function is called also during initialization of ;; tramp-cache.el. `tramp-messageĀ“ is not defined yet at this ;; time, so we ignore the corresponding error. @@ -211,6 +215,7 @@ KEY identifies the connection, it is either a process or a vector." (when (vectorp key) (setq key (copy-sequence key)) (aset key 3 nil)) + (setq tramp-cache-data-changed t) (remhash key tramp-cache-data)) (defun tramp-cache-print (table) @@ -246,39 +251,40 @@ KEY identifies the connection, it is either a process or a vector." (defun tramp-dump-connection-properties () "Write persistent connection properties into file `tramp-persistency-file-name'." ;; We shouldn't fail, otherwise (X)Emacs might not be able to be closed. - (condition-case nil - (when (and (hash-table-p tramp-cache-data) - (not (zerop (hash-table-count tramp-cache-data))) - (stringp tramp-persistency-file-name)) - (let ((cache (copy-hash-table tramp-cache-data))) - ;; Remove temporary data. - (maphash - '(lambda (key value) - (if (and (vectorp key) (not (tramp-file-name-localname key))) - (progn - (remhash "process-name" value) - (remhash "process-buffer" value)) - (remhash key cache))) - cache) - ;; Dump it. - (with-temp-buffer - (insert - ";; -*- emacs-lisp -*-" - ;; `time-stamp-string' might not exist in all (X)Emacs flavors. - (condition-case nil - (progn - (format - " <%s %s>\n" - (time-stamp-string "%02y/%02m/%02d %02H:%02M:%02S") - tramp-persistency-file-name)) - (error "\n")) - ";; Tramp connection history. Don't change this file.\n" - ";; You can delete it, forcing Tramp to reapply the checks.\n\n" - (with-output-to-string - (pp (read (format "(%s)" (tramp-cache-print cache)))))) - (write-region - (point-min) (point-max) tramp-persistency-file-name)))) - (error nil))) + (when tramp-cache-data-changed + (condition-case nil + (when (and (hash-table-p tramp-cache-data) + (not (zerop (hash-table-count tramp-cache-data))) + (stringp tramp-persistency-file-name)) + (let ((cache (copy-hash-table tramp-cache-data))) + ;; Remove temporary data. + (maphash + '(lambda (key value) + (if (and (vectorp key) (not (tramp-file-name-localname key))) + (progn + (remhash "process-name" value) + (remhash "process-buffer" value)) + (remhash key cache))) + cache) + ;; Dump it. + (with-temp-buffer + (insert + ";; -*- emacs-lisp -*-" + ;; `time-stamp-string' might not exist in all (X)Emacs flavors. + (condition-case nil + (progn + (format + " <%s %s>\n" + (time-stamp-string "%02y/%02m/%02d %02H:%02M:%02S") + tramp-persistency-file-name)) + (error "\n")) + ";; Tramp connection history. Don't change this file.\n" + ";; You can delete it, forcing Tramp to reapply the checks.\n\n" + (with-output-to-string + (pp (read (format "(%s)" (tramp-cache-print cache)))))) + (write-region + (point-min) (point-max) tramp-persistency-file-name)))) + (error nil)))) (add-hook 'kill-emacs-hook 'tramp-dump-connection-properties) (add-hook 'tramp-cache-unload-hook @@ -313,7 +319,8 @@ for all methods. Resulting data are derived from connection history." (while (setq element (pop list)) (setq key (pop element)) (while (setq item (pop element)) - (tramp-set-connection-property key (pop item) (car item)))))) + (tramp-set-connection-property key (pop item) (car item))))) + (setq tramp-cache-data-changed nil)) (file-error ;; Most likely because the file doesn't exist yet. No message. (clrhash tramp-cache-data)) -- 2.39.2