fix: scan vaults whose own folder name starts with a dot

A vault kept in a dot-named folder such as ~/.notes was treated as hidden
by seven vault walkers, so All Notes, note titles for links, Graph View,
Tasks and rename link updates found no notes. Exempt the vault root from
the hidden-folder check, as the tag scan and search already do. Hidden
subfolders, .helixnotes and the existing hidden-name rules are unchanged.
This commit is contained in:
Yuri Karamian committed 2026-10-07 21:03:49 +02:00
1 parent ac2c0aef94
commit b2c306d69f
2 files changed
+100 -7

No files matched your search

+42 -3
View File
@@ -1026,7 +1026,9 @@ fn scan_all_note_titles(vault_path: &str) -> Result<Vec<NoteTitleEntry>, String>
.into_iter()
// Cross-platform exclusion (string "/.helixnotes/" checks miss Windows
// backslash paths, which leaked .helixnotes/history snapshots in as dupes).
.filter_entry(|e| !operations::is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
.filter_entry(|e| {
e.depth() == 0 || (!operations::is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
})
.filter_map(|e| e.ok())
.filter(|e| {
e.path().is_file() && e.path().extension().and_then(|x| x.to_str()) == Some("md")
@@ -1134,7 +1136,9 @@ fn scan_graph_data(vault_path: &str) -> Result<crate::types::GraphData, String>
// Windows backslash paths; is_hidden also covers .stversions/.stfolder/.trash/.git).
let candidates: Vec<PathBuf> = walkdir::WalkDir::new(vault)
.into_iter()
.filter_entry(|e| !operations::is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
.filter_entry(|e| {
e.depth() == 0 || (!operations::is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
})
.filter_map(|e| e.ok())
.filter(|entry| {
let path = entry.path();
@@ -1335,7 +1339,8 @@ fn scan_tasks(vault_path: &str, note_path: Option<&str>) -> Result<Vec<TaskItem>
let paths: Vec<PathBuf> = walkdir::WalkDir::new(vault)
.into_iter()
.filter_entry(|entry| {
!operations::is_hidden(entry.path()) && !entry.path().starts_with(&hn_dir)
entry.depth() == 0
|| (!operations::is_hidden(entry.path()) && !entry.path().starts_with(&hn_dir))
})
.filter_map(|entry| entry.ok())
.filter(|entry| {
@@ -1520,6 +1525,40 @@ mod graph_scan_tests {
}
}
#[cfg(test)]
mod dot_named_vault_tests {
use super::{scan_all_note_titles, scan_graph_data, scan_tasks};
use std::fs;
#[test]
fn vault_scans_do_not_treat_a_dot_named_vault_folder_as_hidden() {
// tempdir() names its folder ".tmpXXXX", like a vault kept in ~/.notes.
let vault = tempfile::tempdir().unwrap();
assert!(vault
.path()
.file_name()
.unwrap()
.to_string_lossy()
.starts_with('.'));
let vault_path = vault.path().to_str().unwrap();
fs::write(
vault.path().join("A.md"),
"---\ntitle: Alpha\n---\n[[Beta]]\n- [ ] Task\n",
)
.unwrap();
fs::write(
vault.path().join("B.md"),
"---\ntitle: Beta\n---\n[[Alpha]]\n",
)
.unwrap();
assert_eq!(scan_all_note_titles(vault_path).unwrap().len(), 2);
let graph = scan_graph_data(vault_path).unwrap();
assert_eq!((graph.nodes.len(), graph.edges.len()), (2, 1));
assert_eq!(scan_tasks(vault_path, None).unwrap().len(), 1);
}
}
#[cfg(test)]
mod task_tests {
use super::scan_tasks;
+58 -4
View File
@@ -549,7 +549,9 @@ pub fn scan_notes(vault_path: &str, notebook_path: Option<&str>) -> Result<Vec<N
WalkDir::new(root)
.into_iter()
// filter_entry skips descending into hidden dirs (unlike filter)
.filter_entry(|e| !is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
.filter_entry(|e| {
e.depth() == 0 || (!is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
})
.filter_map(|e| e.ok())
.map(|e| e.path().to_path_buf())
.filter(|p| p.is_file() && p.extension().and_then(|x| x.to_str()) == Some("md"))
@@ -579,7 +581,9 @@ pub fn scan_notes(vault_path: &str, notebook_path: Option<&str>) -> Result<Vec<N
WalkDir::new(root)
.into_iter()
.filter_entry(|e| {
!is_hidden(e.path()) && !e.path().starts_with(helixnotes_dir(vault_path))
e.depth() == 0
|| (!is_hidden(e.path())
&& !e.path().starts_with(helixnotes_dir(vault_path)))
})
.filter_map(|e| e.ok())
.map(|e| e.path().to_path_buf())
@@ -1356,7 +1360,9 @@ fn update_wikilinks_after_rename(
// vs. the other note with the same title.
let title_is_unique = !WalkDir::new(vault)
.into_iter()
.filter_entry(|e| !is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
.filter_entry(|e| {
e.depth() == 0 || (!is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
})
.filter_map(|e| e.ok())
.any(|e| {
let p = e.path();
@@ -1375,7 +1381,9 @@ fn update_wikilinks_after_rename(
for entry in WalkDir::new(vault)
.into_iter()
.filter_entry(|e| !is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
.filter_entry(|e| {
e.depth() == 0 || (!is_hidden(e.path()) && !e.path().starts_with(&hn_dir))
})
.filter_map(|e| e.ok())
{
let path = entry.path();
@@ -3658,6 +3666,52 @@ mod tests {
assert_eq!(super::read_note_head(&path).unwrap(), "---\n---\nShort");
}
#[test]
fn dot_named_vault_folder_is_still_scanned_and_renames_update_links() {
// tempdir() names its folder ".tmpXXXX", like a vault kept in ~/.notes.
let vault = tempfile::tempdir().unwrap();
assert!(vault
.path()
.file_name()
.unwrap()
.to_string_lossy()
.starts_with('.'));
let vault_path = vault.path().to_str().unwrap();
fs::write(vault.path().join("Old.md"), "---\ntitle: Old\n---\n# Old\n").unwrap();
let other = vault.path().join("Other.md");
fs::write(&other, "---\ntitle: Other\n---\nSee [[Old]].\n").unwrap();
assert_eq!(super::scan_notes(vault_path, None).unwrap().len(), 2);
fs::create_dir(vault.path().join("Notebook")).unwrap();
fs::write(
vault.path().join("Notebook/Tagged.md"),
"---\ntags: [work]\n---\n# Tagged\n",
)
.unwrap();
assert_eq!(super::scan_notebooks(vault_path).unwrap().len(), 1);
assert_eq!(
super::get_all_tags(vault_path).unwrap(),
[("work".to_string(), 1)]
);
assert_eq!(
super::scan_notes(
vault_path,
Some(vault.path().join("Notebook").to_str().unwrap())
)
.unwrap()
.len(),
1
);
super::rename_note(
vault.path().join("Old.md").to_str().unwrap(),
"Renamed",
vault_path,
)
.unwrap();
assert!(fs::read_to_string(other).unwrap().contains("Renamed"));
}
#[test]
fn vault_state_save_replaces_file_without_truncating_open_reader() {
let vault = tempfile::tempdir().unwrap();