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

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

[elpa] externals/org 8b8a65ed02 08/10: org-persist: Introduce "associate


From: ELPA Syncer
Subject: [elpa] externals/org 8b8a65ed02 08/10: org-persist: Introduce "associated files" for GC
Date: Sun, 11 Dec 2022 02:57:58 -0500 (EST)

branch: externals/org
commit 8b8a65ed02153479d765e33c4af51bf49dd86463
Author: TEC <git@tecosaur.net>
Commit: TEC <git@tecosaur.net>

    org-persist: Introduce "associated files" for GC
    
    * lisp/org-persist.el (org-persist-gc, org-persist--associated-files,
    org-persist--associated-files:url): The url container stores downloaded
    files separately within `org-persist-directory', which means that
    `org-persist-gc' picks them up as "orphan files" and deletes them every
    time it is called.  To avoid this collateral damage, a new family of
    collection-specific functions is introduced,
    "org-persist--associated-files:COLLECTION".  This allows collections to
    tell GC about associated files that should be left alone, and is used
    for url collections to preserve downloaded files.
---
 lisp/org-persist.el | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lisp/org-persist.el b/lisp/org-persist.el
index 01ed8c3f8e..1fa2c047a7 100644
--- a/lisp/org-persist.el
+++ b/lisp/org-persist.el
@@ -929,6 +929,23 @@ Do nothing in an indirect buffer."
     (when (org-directory-empty-p (file-name-directory persist-file))
       (delete-directory (file-name-directory persist-file)))))
 
+(defmacro org-persist--associated-files:generic (container collection)
+  "List associated files in `org-persist-directory' for CONTAINER in 
COLLECTION."
+  `(let* ((c (org-persist--normalize-container ,container))
+          (gc-func-symbol (intern (format "org-persist--associated-files:%s" 
(car c)))))
+     (and (fboundp gc-func-symbol)
+          (funcall gc-func-symbol c ,collection))))
+
+(defun org-persist--associated-files:url (_ collection)
+  "List url-associated files in `org-persist-directory' for COLLECTION."
+  (let* ((persist-file (org-file-name-concat
+                        org-persist-directory
+                        (plist-get collection :persist-file)))
+         (data (or (gethash persist-file org-persist--write-cache)
+                   (org-persist--read-elisp-file persist-file)))
+         (url-file (alist-get '(url nil) data nil nil #'equal)))
+    (and url-file (list url-file))))
+
 (defun org-persist-gc ()
   "Remove expired or unregistered containers and orphaned files.
 Also, remove containers associated with non-existing files."
@@ -968,7 +985,16 @@ Also, remove containers associated with non-existing 
files."
                 (setq expired? t)))
             (if expired?
                 (org-persist--gc-persist-file persist-file)
-              (push collection new-index)))))
+              (push collection new-index)
+              (dolist (container (plist-get collection :container))
+                (dolist (associated-file
+                         (org-persist--associated-files:generic
+                          container collection))
+                  (setq orphan-files
+                        (delete (org-file-name-concat
+                                 org-persist-directory
+                                 associated-file)
+                                orphan-files))))))))
       (mapc #'org-persist--gc-persist-file orphan-files)
       (setq org-persist--index (nreverse new-index)))))
 



reply via email to

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