0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-25 14:02:51 +00:00

org-persist-write-all: Do not create index with no containers

* lisp/org-persist.el (org-persist-write-all): Do not create
`org-persist-directory' when index does not contain any data except
index version.

Link: https://orgmode.org/list/875yedw0ib.fsf@localhost
This commit is contained in:
Ihor Radchenko 2022-12-17 12:34:14 +03:00
parent 81f2741bca
commit aa86ed534f
No known key found for this signature in database
GPG key ID: 6470762A7DA11D8B

View file

@ -881,26 +881,35 @@ 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))
(let (all-containers)
(dolist (collection org-persist--index)
(if associated
(when collection
(cl-pushnew (plist-get collection :container) all-containers :test #'equal))
(condition-case err
(org-persist-write (plist-get collection :container) (plist-get collection :associated) t)
(error
(message "%s. Deleting bad index entry." err)
(org-persist--remove-from-index collection)
nil))))
(dolist (container all-containers)
(let ((collection (org-persist--find-index `(:container ,container :associated ,associated))))
(when collection
(unless
(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)))
(let (all-containers)
(dolist (collection org-persist--index)
(if associated
(when collection
(cl-pushnew (plist-get collection :container) all-containers :test #'equal))
(condition-case err
(org-persist-write container associated t)
(org-persist-write (plist-get collection :container) (plist-get collection :associated) t)
(error
(message "%s. Deleting bad index entry." err)
(org-persist--remove-from-index collection)
nil)))))))
nil))))
(dolist (container all-containers)
(let ((collection (org-persist--find-index `(:container ,container :associated ,associated))))
(when collection
(condition-case err
(org-persist-write container associated t)
(error
(message "%s. Deleting bad index entry." err)
(org-persist--remove-from-index collection)
nil))))))))
(defun org-persist-write-all-buffer ()
"Call `org-persist-write-all' in current buffer.