forked from mirrors/org-mode
org-persist: Fallback to associated files in write
* lisp/org-persist.el (org-persist-write:file): If the path given in a file container does not exist, instead of returning nothing return the associated path if possible. This fixes an issue where should the original file be deleted and `org-persist-write-all' be run, then the file container's association will be set to nil and so when `org-persist-gc' is run the nil path will cause org-persist-associated-files:file to produce an error.
This commit is contained in:
parent
eb7e65bcaf
commit
90cb3e9507
|
@ -828,20 +828,23 @@ COLLECTION is the plist holding data collection."
|
||||||
(defun org-persist-write:file (c collection)
|
(defun org-persist-write:file (c collection)
|
||||||
"Write file container C according to COLLECTION."
|
"Write file container C according to COLLECTION."
|
||||||
(org-persist-collection-let collection
|
(org-persist-collection-let collection
|
||||||
(when (or (and path (file-exists-p path))
|
(if (or (and path (file-exists-p path))
|
||||||
(and (stringp (cadr c)) (file-exists-p (cadr c))))
|
(and (stringp (cadr c)) (file-exists-p (cadr c))))
|
||||||
(when (and (stringp (cadr c)) (file-exists-p (cadr c)))
|
(progn
|
||||||
(setq path (cadr c)))
|
(when (and (stringp (cadr c)) (file-exists-p (cadr c)))
|
||||||
(let* ((persist-file (plist-get collection :persist-file))
|
(setq path (cadr c)))
|
||||||
(ext (file-name-extension path))
|
(let* ((persist-file (plist-get collection :persist-file))
|
||||||
(file-copy (org-file-name-concat
|
(ext (file-name-extension path))
|
||||||
org-persist-directory
|
(file-copy (org-file-name-concat
|
||||||
(format "%s-%s.%s" persist-file (md5 path) ext))))
|
org-persist-directory
|
||||||
(unless (file-exists-p file-copy)
|
(format "%s-%s.%s" persist-file (md5 path) ext))))
|
||||||
(unless (file-exists-p (file-name-directory file-copy))
|
(unless (file-exists-p file-copy)
|
||||||
(make-directory (file-name-directory file-copy) t))
|
(unless (file-exists-p (file-name-directory file-copy))
|
||||||
(copy-file path file-copy 'overwrite))
|
(make-directory (file-name-directory file-copy) t))
|
||||||
(format "%s-%s.%s" persist-file (md5 path) ext)))))
|
(copy-file path file-copy 'overwrite))
|
||||||
|
(format "%s-%s.%s" persist-file (md5 path) ext)))
|
||||||
|
(when-let ((file-copy (org-persist-read c associated)))
|
||||||
|
(file-relative-name file-copy org-persist-directory)))))
|
||||||
|
|
||||||
(defun org-persist-write:url (c collection)
|
(defun org-persist-write:url (c collection)
|
||||||
"Write url container C according to COLLECTION."
|
"Write url container C according to COLLECTION."
|
||||||
|
|
Loading…
Reference in New Issue