emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org d2b49c72b2: Merge branch 'bugfix'


From: ELPA Syncer
Subject: [elpa] externals/org d2b49c72b2: Merge branch 'bugfix'
Date: Sun, 25 Dec 2022 04:57:55 -0500 (EST)

branch: externals/org
commit d2b49c72b22c02a558d4d065bf468fc2f03d9a1a
Merge: f731d45d28 987fe173ac
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    Merge branch 'bugfix'
---
 lisp/org-persist.el | 50 ++++++++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 16 deletions(-)

diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index 94e0afdee5..ced620f465 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -915,15 +915,21 @@ When IGNORE-RETURN is non-nil, just return t on success 
without calling
 When ASSOCIATED is non-nil, only save the matching data."
   (unless org-persist--index (org-persist--load-index))
   (setq associated (org-persist--normalize-associated associated))
-  (unless
+  (if
       (and (equal 1 (length org-persist--index))
            ;; The single collection only contains a single container
            ;; in the container list.
            (equal 1 (length (plist-get (car org-persist--index) :container)))
            ;; The container is an `index' container.
            (eq 'index (caar (plist-get (car org-persist--index) :container)))
-           ;; No `org-persist-directory' exists yet.
-           (not (file-exists-p org-persist-directory)))
+           (or (not (file-exists-p org-persist-directory))
+               (org-directory-empty-p org-persist-directory)))
+      ;; Do not write anything, and clear up `org-persist-directory' to reduce
+      ;; clutter.
+      (when (and (file-exists-p org-persist-directory)
+                 (org-directory-empty-p org-persist-directory))
+        (delete-directory org-persist-directory))
+    ;; Write the data.
     (let (all-containers)
       (dolist (collection org-persist--index)
         (if associated
@@ -1036,6 +1042,30 @@ Also, remove containers associated with non-existing 
files."
     (mapc #'org-persist--gc-persist-file orphan-files)
     (setq org-persist--index (nreverse new-index))))
 
+(defun org-persist-clear-storage-maybe ()
+  "Clear `org-persist-directory' according to 
`org-persist--disable-when-emacs-Q'.
+
+When `org-persist--disable-when-emacs-Q' is non-nil and Emacs is called with -Q
+command line argument, `org-persist-directory' is created in potentially public
+system temporary directory.  Remove everything upon existing Emacs in
+such scenario."
+  (when (and org-persist--disable-when-emacs-Q
+             ;; FIXME: This is relying on undocumented fact that
+             ;; Emacs sets `user-init-file' to nil when loaded with
+             ;; "-Q" argument.
+             (not user-init-file)
+             (file-exists-p org-persist-directory))
+    (delete-directory org-persist-directory 'recursive)))
+
+;; Point to temp directory when `org-persist--disable-when-emacs-Q' is set.
+(when (and org-persist--disable-when-emacs-Q
+           ;; FIXME: This is relying on undocumented fact that
+           ;; Emacs sets `user-init-file' to nil when loaded with
+           ;; "-Q" argument.
+           (not user-init-file))
+  (setq org-persist-directory
+        (make-temp-file "org-persist-" 'dir)))
+
 ;; Automatically write the data, but only when we have write access.
 (let ((dir (directory-file-name
             (file-name-as-directory org-persist-directory))))
@@ -1045,24 +1075,12 @@ Also, remove containers associated with non-existing 
files."
   (if (not (file-writable-p dir))
       (message "Missing write access rights to org-persist-directory: %S"
                org-persist-directory)
+    (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)))
 
-;; Point to temp directory when `org-persist--disable-when-emacs-Q' is set.
-(when (and org-persist--disable-when-emacs-Q
-           ;; FIXME: This is relying on undocumented fact that
-           ;; Emacs sets `user-init-file' to nil when loaded with
-           ;; "-Q" argument.
-           (not user-init-file))
-  (setq org-persist-directory
-        (make-temp-file "org-persist-" 'dir))
-  ;; We don't need the temp directory to exist.
-  ;; `org-persist-write-all' will refrain from creating and writing to the dir 
if
-  ;; none exists yet.
-  (delete-directory org-persist-directory))
-
 (add-hook 'after-init-hook #'org-persist-load-all)
 
 (provide 'org-persist)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]