From f50d6e7376b3ba603fb4df1d95204ca5f3cc3ca8 Mon Sep 17 00:00:00 2001 From: PRESFIL Date: Fri, 4 Mar 2022 09:47:24 +0300 Subject: [PATCH] (fix): caching symlinked files (#2112) * Revert "(fix): `org-roam-descendant-of-p` bug on Windows (#2089)" This reverts commit 97a342fd3f0472e49407f38a136183231a556242. Reason: It seems that the `file-in-directory-p` function proposed in #2089 is provided only for *physical directories*, does not work as we would like with *symlinked directories*. It dereferences all the symlinks in its path, and previously seemed related paths cease to be such. Because of this, such notes are ignored and not indexed, although they were indexed earlier. --- extensions/org-roam-dailies.el | 2 +- org-roam-utils.el | 7 +++++++ org-roam.el | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/extensions/org-roam-dailies.el b/extensions/org-roam-dailies.el index 5d63882..e82d55d 100644 --- a/extensions/org-roam-dailies.el +++ b/extensions/org-roam-dailies.el @@ -289,7 +289,7 @@ If FILE is not specified, use the current buffer's file-path." (save-match-data (and (org-roam-file-p path) - (file-in-directory-p path directory))))) + (org-roam-descendant-of-p path directory))))) ;;;###autoload (defun org-roam-dailies-find-directory () diff --git a/org-roam-utils.el b/org-roam-utils.el index 9d3ccce..8d30de0 100644 --- a/org-roam-utils.el +++ b/org-roam-utils.el @@ -108,6 +108,13 @@ SPEC is a list, as per `dolist'." `(dolist-with-progress-reporter ,spec ,msg ,@body) `(dolist ,spec ,@body))) +;;; File utilities +(defun org-roam-descendant-of-p (a b) + "Return t if A is descendant of B." + (unless (equal (file-truename a) (file-truename b)) + (string-prefix-p (replace-regexp-in-string "^\\([A-Za-z]\\):" 'downcase (expand-file-name b) t t) + (replace-regexp-in-string "^\\([A-Za-z]\\):" 'downcase (expand-file-name a) t t)))) + (defmacro org-roam-with-file (file keep-buf-p &rest body) "Execute BODY within FILE. If FILE is nil, execute BODY in the current buffer. diff --git a/org-roam.el b/org-roam.el index 5b7b0f3..d1d75e6 100644 --- a/org-roam.el +++ b/org-roam.el @@ -194,7 +194,7 @@ FILE is an Org-roam file if: (member ext org-roam-file-extensions) (not (and org-roam-file-exclude-regexp (string-match-p org-roam-file-exclude-regexp path))) - (file-in-directory-p path (expand-file-name org-roam-directory)))))) + (org-roam-descendant-of-p path (expand-file-name org-roam-directory)))))) (defun org-roam-list-files () "Return a list of all Org-roam files under `org-roam-directory'.