(fix): fix rename file corrupting database (#1308)

The rename file advice is passed relative file names: e.g. "foo.org" ->
"bar.org". This was not accounted for, and paths in the Org-roam
database are supposed to be absolute paths. This caused the storing of
relative paths in the Org-roam database, which were then never purged.

Fixes #1304
This commit is contained in:
Jethro Kuan
2020-11-19 22:26:59 +08:00
committed by GitHub
parent b17cc3b1e3
commit ab34dd138d
3 changed files with 41 additions and 37 deletions

View File

@ -255,15 +255,14 @@ This function is called on `org-roam-db-file-update-timer'."
(dolist (table (mapcar #'car org-roam-db--table-schemata))
(org-roam-db-query `[:delete :from ,table]))))
(defun org-roam-db--clear-file (&optional filepath)
"Remove any related links to the file at FILEPATH.
(defun org-roam-db--clear-file (&optional file)
"Remove any related links to the FILE.
This is equivalent to removing the node from the graph."
(let ((file (expand-file-name (or filepath
(buffer-file-name (buffer-base-buffer))))))
(dolist (table (mapcar #'car org-roam-db--table-schemata))
(org-roam-db-query `[:delete :from ,table
:where (= ,(if (eq table 'links) 'source 'file) $s1)]
file))))
(setq file (or file (buffer-file-name (buffer-base-buffer))))
(dolist (table (mapcar #'car org-roam-db--table-schemata))
(org-roam-db-query `[:delete :from ,table
:where (= ,(if (eq table 'links) 'source 'file) $s1)]
file)))
;;;;; Inserting
(defun org-roam-db--insert-meta (&optional update-p)