summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/multisession.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-12-16 08:00:01 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-12-16 08:00:01 +0100
commited77d1a8c0f005d4f158b635d39db0d5d79fe1ee (patch)
treee55bf48d436d0e8edc1ce3f9313e76f1d4720825 /lisp/emacs-lisp/multisession.el
parentbc60ce7ffdf39fc3288938337e7f6c0706b37082 (diff)
downloademacs-ed77d1a8c0f005d4f158b635d39db0d5d79fe1ee.tar.gz
emacs-ed77d1a8c0f005d4f158b635d39db0d5d79fe1ee.tar.bz2
emacs-ed77d1a8c0f005d4f158b635d39db0d5d79fe1ee.zip
Make the multisession files value read more resilient
* lisp/emacs-lisp/multisession.el (multisession--update-file-value): Make more resilient towards errors.
Diffstat (limited to 'lisp/emacs-lisp/multisession.el')
-rw-r--r--lisp/emacs-lisp/multisession.el25
1 files changed, 16 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/multisession.el b/lisp/emacs-lisp/multisession.el
index 0216057831a..cc7fc53d03d 100644
--- a/lisp/emacs-lisp/multisession.el
+++ b/lisp/emacs-lisp/multisession.el
@@ -252,15 +252,22 @@ DOC should be a doc string, and ARGS are keywords as applicable to
(url-hexify-string name))
(defun multisession--update-file-value (file object)
- (with-temp-buffer
- (let* ((time (file-attribute-modification-time
- (file-attributes file)))
- (coding-system-for-read 'utf-8))
- (insert-file-contents file)
- (let ((stored (read (current-buffer))))
- (setf (multisession--cached-value object) stored
- (multisession--cached-sequence object) time)
- stored))))
+ (condition-case nil
+ (with-temp-buffer
+ (let* ((time (file-attribute-modification-time
+ (file-attributes file)))
+ (coding-system-for-read 'utf-8))
+ (insert-file-contents file)
+ (let ((stored (read (current-buffer))))
+ (setf (multisession--cached-value object) stored
+ (multisession--cached-sequence object) time)
+ stored)))
+ ;; If the file is contended (could happen with file locking in
+ ;; Windws) or unreadable, just return the current value.
+ (error
+ (if (eq (multisession--cached-value object) multisession--unbound)
+ (multisession--initial-value object)
+ (multisession--cached-value object)))))
(defun multisession--object-file-name (object)
(expand-file-name