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): keep a backslash that is part of a Unix filename (#1669)
xerj-orgacaa2206e0d3
diff --git a/engine/crates/xerj-autoindex/src/walk.rs b/engine/crates/xerj-autoindex/src/walk.rsindex e6c45a437..8b0adde6e 100644--- a/engine/crates/xerj-autoindex/src/walk.rs+++ b/engine/crates/xerj-autoindex/src/walk.rs@@ -14,7 +14,8 @@ use std::path::{Path, PathBuf};#[derive(Debug, Clone)]pub struct FileEntry {pub path: PathBuf,- /// Root-relative path with forward slashes — the stable `ax_path` value.+ /// Root-relative `ax_path`. On Windows `\` is the separator and is written+ /// as `/`. On Unix `\` is a filename character and is kept.pub rel: String,/// Reversible platform-native identity; unlike `rel`, never lossy.pub rel_id: String,@@ -507,11 +508,7 @@ fn walk_impl(Err(_) => continue,};let p = entry.path().to_path_buf();- let rel = p- .strip_prefix(&root_canon)- .unwrap_or(&p)- .to_string_lossy()- .replace('\\', "/");+ let rel = portable_rel(p.strip_prefix(&root_canon).unwrap_or(&p));let rel_id = stable_path_id(p.strip_prefix(&root_canon).unwrap_or(&p));out.push(FileEntry {path: resolved.unwrap_or(p),@@ -529,6 +526,21 @@ fn walk_impl(Ok((out, stack.report))}+/// `ax_path` text for one root-relative path.+///+/// Windows uses `\` as a separator, so the stored path uses `/`. Everywhere+/// else `\` is part of the name: rewriting it invents a directory+/// (`src/utils/win\name.rs` became `src/utils/win/name.rs`, which is not on+/// disk) and collides with a real `win/name.rs`.+pub(crate) fn portable_rel(rel: &Path) -> String {+ let text = rel.to_string_lossy();+ if cfg!(windows) {+ text.replace('\\', "/")+ } else {+ text.into_owned()+ }+}+#[cfg(unix)]fn stable_path_id(path: &Path) -> String {use std::os::unix::ffi::OsStrExt;@@ -1173,3 +1185,45 @@ mod takeout_noise_tests {}}}++#[cfg(test)]+mod portable_rel_tests {+ use super::{portable_rel, walk_reporting};+ use crate::ignore_rules::IgnoreOptions;+ use std::path::Path;++ #[test]+ fn portable_rel_keeps_a_unix_backslash_and_rewrites_windows_separators() {+ #[cfg(not(windows))]+ {+ let rel = portable_rel(Path::new("src/utils/win\\name.rs"));+ assert_eq!(rel, "src/utils/win\\name.rs");+ assert!(!rel.contains("win/name.rs"), "{rel}");+ }+ #[cfg(windows)]+ {+ let rel = portable_rel(Path::new("src\\utils\\name.rs"));+ assert_eq!(rel, "src/utils/name.rs");+ }+ }++ /// The string helper is not the walk. A real file whose name contains+ /// `\` must come back with that character still in `FileEntry.rel`.+ #[cfg(not(windows))]+ #[test]+ fn a_walk_keeps_a_backslash_that_is_part_of_the_filename() {+ let dir = tempfile::tempdir().unwrap();+ let utils = dir.path().join("src").join("utils");+ std::fs::create_dir_all(&utils).unwrap();+ std::fs::write(utils.join("win\\name.rs"), "fn weird() {}\n").unwrap();+ std::fs::write(utils.join("paths.rs"), "fn open_path() {}\n").unwrap();+ let (files, _) = walk_reporting(dir.path(), false, IgnoreOptions::default()).unwrap();+ let rels: Vec<&str> = files.iter().map(|f| f.rel.as_str()).collect();+ assert!(rels.contains(&"src/utils/win\\name.rs"), "{rels:?}");+ assert!(+ rels.iter().all(|rel| !rel.contains("win/name.rs")),+ "{rels:?}"+ );+ assert!(rels.contains(&"src/utils/paths.rs"), "{rels:?}");+ }+}