Andreas Röhler <[email protected]> writes:
> ;; Automatically write the data, but only when we have write access.
> (when (org-persist--check-write-access org-persist-directory)
> + (unless (string= "root" (getenv "USER"))
> (add-hook 'kill-emacs-hook #'org-persist-clear-storage-maybe) ;
> Run last.
> (add-hook 'kill-emacs-hook #'org-persist-write-all)
> ;; `org-persist-gc' should run before `org-persist-write-all'.
> ;; So we are adding the hook after `org-persist-write-all'.
> - (add-hook 'kill-emacs-hook #'org-persist-gc))
> + (add-hook 'kill-emacs-hook #'org-persist-gc)))
This will not be enough because some parts of the code force writing
cache. Disabling the cleanup will simply make things worse in your
situation.
> The issue occurred at NixOS when running Emacs as root in order to edit
> configuration.nix.
> ...
> Debugger entered--Lisp error: (permission-denied "Opening input file"
> "Permission denied" "/home/MySelf/.cache/org-persist/index.eld")
> insert-file-contents("/home/MySelf/.cache/org-persist/index.eld")
> org-persist--read-elisp-file("/home/MySelf/.cache/org-persist/index.eld")
> org-persist-read:index((index "3.2")
> "/home/MySelf/.cache/org-persist/index.eld" nil)
> org-persist-load:index((index "3.2")
Can you try the attached patch?
>From 65b87dab6f8b7142ac4a9db7a6a71c5c1a982f6c Mon Sep 17 00:00:00 2001
Message-ID: <65b87dab6f8b7142ac4a9db7a6a71c5c1a982f6c.1754226853.git.yanta...@posteo.net>
From: Ihor Radchenko <[email protected]>
Date: Sun, 3 Aug 2025 15:13:03 +0200
Subject: [PATCH] org-persist: Fix edge case when we have no permission to read
index file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* lisp/org-persist.el (org-persist-read:index): Do not try reading
index file we have no permission to read.
Reported-by: Andreas Röhler <[email protected]>
Link: https://orgmode.org/list/[email protected]
---
lisp/org-persist.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index d2c5f6760..cb69a9380 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -760,7 +760,7 @@ (defun org-persist-read:url (_ path __)
(defun org-persist-read:index (cont index-file _)
"Read index container CONT from INDEX-FILE."
- (when (file-exists-p index-file)
+ (when (and (file-exists-p index-file) (file-readable-p index-file))
(let ((index (org-persist--read-elisp-file index-file)))
(when index
(catch :found
--
2.50.1
--
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>