AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(autoindex): align dry-run hidden count and document upgrade
Sebastien Tardif89a7b9d92838
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f51fd0887..624204c89 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -145,7 +145,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0used `file_name().to_str().starts_with('.')`. On Unix a name whosefirst byte is `.` and that is not valid UTF-8 (`to_str()` is `None`)was walked and indexed. The skip now compares the first encoded byte- to `.`. Typical UTF-8 secrets were already skipped.+ to `.`. Typical UTF-8 secrets were already skipped. `--dry-run`'s+ `ignored_files_in_pruned_dirs` count uses the same predicate, so a+ hidden non-UTF-8 file (or the contents of a hidden non-UTF-8+ directory) is no longer reported as a non-hidden file inside a+ pruned directory.++ **Upgrade.** A corpus indexed by a pre-fix binary that contains a+ hidden non-UTF-8 name looks like a file removal to the graph-enabled+ path (the default, and what `xerj brain` uses). Until+ [#439](https://github.com/xerj-org/xerj/issues/439) lands, the first+ rerun exits 1 with `unsupported_content_group_removal`, writes+ nothing, and the already-indexed documents stay live. Do not follow+ the refusal's first recovery route ("restore the removed file(s)"):+ the file is still on disk, just no longer walked. Recovery that+ works: delete the published indices and the state directory, then+ re-index the folder. An isolated rebuild with a new `--state-dir` /+ `--prefix` also exits 0, but leaves the old target's documents live+ until those indices are deleted by hand.- **Autoindex snapshot and replay one-shot failpoints can no longer be stolen by unrelated parallel tests.** ([#385](https://github.com/xerj-org/xerj/issues/385)).The two test-only failpoints are now owned by the thread that arms them, whilediff --git a/engine/crates/xerj-autoindex/src/ignore_rules.rs b/engine/crates/xerj-autoindex/src/ignore_rules.rsindex 95a561f62..61037a0de 100644--- a/engine/crates/xerj-autoindex/src/ignore_rules.rs+++ b/engine/crates/xerj-autoindex/src/ignore_rules.rs@@ -61,8 +61,16 @@use ignore::gitignore::{Gitignore, GitignoreBuilder, Glob};use ignore::Match;use std::collections::BTreeMap;+use std::ffi::OsStr;use std::path::{Path, PathBuf};+/// Hidden names start with `.` even when they are not valid UTF-8.+/// `OsStr::to_str()` is `None` for those, so a UTF-8 `starts_with('.')`+/// would walk them (and, here, would count them as non-hidden).+pub(crate) fn is_hidden_name(name: &OsStr) -> bool {+ name.as_encoded_bytes().first() == Some(&b'.')+}+/// Ignore file honoured in every directory, ranked below `.xerjignore`.pub const GITIGNORE: &str = ".gitignore";/// XERJ's own ignore file. Same syntax as `.gitignore`, higher precedence, so@@ -730,11 +738,7 @@ impl IgnoreStack {.follow_links(false).min_depth(1).into_iter()- .filter_entry(|e| {- !e.file_name()- .to_str()- .is_some_and(|name| name.starts_with('.'))- });+ .filter_entry(|e| !is_hidden_name(e.file_name()));for entry in walker {if self.budget == 0 {self.report.deep_count_complete = false;@@ -764,12 +768,7 @@ mod tests {while let Some(next) = it.next() {let Ok(entry) = next else { continue };let is_dir = entry.file_type().is_dir();- if entry.depth() > 0- && entry- .file_name()- .to_str()- .is_some_and(|n| n.starts_with('.'))- {+ if entry.depth() > 0 && is_hidden_name(entry.file_name()) {stack.record_hidden(is_dir);if is_dir {it.skip_current_dir();@@ -1100,6 +1099,47 @@ mod tests {);}+ /// After the walker started treating a non-UTF-8 `.\x80` name as hidden,+ /// `count_inside` still used `to_str().starts_with('.')` and counted those+ /// files (and descended those directories). APFS rejects the name; Linux+ /// does not.+ #[cfg(target_os = "linux")]+ #[test]+ fn count_inside_skips_hidden_non_utf8_names() {+ use std::ffi::OsStr;+ use std::os::unix::ffi::OsStrExt;++ let dir = tempfile::TempDir::new().unwrap();+ let root = dir.path();+ write(root, ".xerjignore", "pruned/\n");+ write(root, "keep.md", "x");+ write(root, "pruned/visible1.txt", "x");+ write(root, "pruned/.hiddenutf8", "x");+ fs::write(+ root.join("pruned").join(OsStr::from_bytes(b".\x80hidden")),+ "x",+ )+ .unwrap();+ fs::create_dir(root.join("pruned").join(OsStr::from_bytes(b".\x80dir"))).unwrap();+ fs::write(+ root.join("pruned")+ .join(OsStr::from_bytes(b".\x80dir"))+ .join("inside.txt"),+ "x",+ )+ .unwrap();++ let (kept, deep) = survivors(root, IgnoreOptions::default().with_deep_count(true));+ assert_eq!(kept, vec!["keep.md".to_string()], "{kept:?}");+ assert_eq!(+ deep.files_inside_pruned_dirs, 1,+ "only pruned/visible1.txt is a non-hidden file inside the pruned \+ tree; .hiddenutf8, .\\x80hidden, and .\\x80dir/inside.txt are \+ hidden: {deep:?}"+ );+ assert!(deep.files_inside_pruned_dirs_is_exact());+ }+/// #279. The claim the reporting makes about its own number, checked as/// arithmetic: what a default run excludes over a `--no-ignore` run is/// exactly the files the rules matched directly plus the files inside thediff --git a/engine/crates/xerj-autoindex/src/walk.rs b/engine/crates/xerj-autoindex/src/walk.rsindex 4213cc642..3e29cc388 100644--- a/engine/crates/xerj-autoindex/src/walk.rs+++ b/engine/crates/xerj-autoindex/src/walk.rs@@ -7,18 +7,10 @@//! descended, so its contents cost nothing — no stat, no hash, no bulk body.//! The matching itself lives in [`crate::ignore_rules`].-use crate::ignore_rules::{IgnoreOptions, IgnoreReport, IgnoreStack};+use crate::ignore_rules::{is_hidden_name, IgnoreOptions, IgnoreReport, IgnoreStack};use anyhow::{Context, Result};-use std::ffi::OsStr;use std::path::{Path, PathBuf};-/// Hidden names start with `.` even when they are not valid UTF-8.-/// `OsStr::to_str()` is `None` for those, so a UTF-8 `starts_with('.')`-/// would walk them.-fn is_hidden_name(name: &OsStr) -> bool {- name.as_encoded_bytes().first() == Some(&b'.')-}-#[derive(Debug, Clone)]pub struct FileEntry {pub path: PathBuf,@@ -279,7 +271,7 @@ mod hidden_skip_tests {#[cfg(unix)]#[test]fn hidden_non_utf8_dot_name_is_detected() {- use super::is_hidden_name;+ use crate::ignore_rules::is_hidden_name;use std::ffi::OsStr;use std::os::unix::ffi::OsStrExt;