Skip to content

armgit / xerj

Public Imported from GitHub
0

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.

fix(autoindex): name symlinks the walk does not follow (#1680)

xerj-org80c88cc3c98f
diff --git a/engine/crates/xerj-autoindex/src/ignore_rules.rs b/engine/crates/xerj-autoindex/src/ignore_rules.rs
index e2fd89fd0..4cfe9c63d 100644
--- a/engine/crates/xerj-autoindex/src/ignore_rules.rs
+++ b/engine/crates/xerj-autoindex/src/ignore_rules.rs
@@ -163,6 +163,14 @@ pub const UNRESOLVED_LINK_RULE: &str = "symlink:unresolved";
/// Both were tried; this names the two facts that are actually true.
pub const HIDDEN_OUTSIDE_ROOT_RULE: &str = "symlink:outside-root+hidden";
+/// A symlink the walk did not follow. The default is not to follow links, and
+/// an unfollowed symlink is not a file to walkdir, so it used to be skipped
+/// with no line on the ignore report — a tree of links looked empty. One
+/// warning names `--follow-symlinks`; each link is counted under this rule.
+/// A target outside the folder stays refused even when the flag is on
+/// ([`ESCAPED_ROOT_RULE`]).
+pub const NOT_FOLLOWED_RULE: &str = "symlink:not-followed";
+
const MAX_WARNINGS: usize = 20;
/// Directory entries the `--dry-run` deep count may examine in total. A
/// pathological `node_modules` is not allowed to turn "tell me the plan" into
@@ -768,6 +776,19 @@ impl IgnoreStack {
}
}
+ /// A symlink left unfollowed. See [`NOT_FOLLOWED_RULE`]. The warning is
+ /// once per walk: the rule count already says how many links.
+ pub fn record_symlink_not_followed(&mut self) {
+ if !self.report.by_rule.contains_key(NOT_FOLLOWED_RULE) {
+ self.warn(
+ "symlink: not followed (pass --follow-symlinks to index a target inside \
+ this folder; a target outside it stays refused)"
+ .into(),
+ );
+ }
+ self.record_file(NOT_FOLLOWED_RULE);
+ }
+
/// A followed entry that could not be resolved. See [`UNRESOLVED_LINK_RULE`].
pub fn record_symlink_unresolved(&mut self, is_dir: bool) {
if is_dir {
diff --git a/engine/crates/xerj-autoindex/src/walk.rs b/engine/crates/xerj-autoindex/src/walk.rs
index 8b0adde6e..67325cd96 100644
--- a/engine/crates/xerj-autoindex/src/walk.rs
+++ b/engine/crates/xerj-autoindex/src/walk.rs
@@ -486,6 +486,12 @@ fn walk_impl(
continue;
}
if !entry.file_type().is_file() {
+ // Unfollowed symlinks are not files to walkdir. Skipping them
+ // with no report made a tree of links look empty: neither the
+ // file list nor the ignore summary mentioned them.
+ if !follow_symlinks && entry.path_is_symlink() {
+ stack.record_symlink_not_followed();
+ }
continue;
}
if stack.skip_file(entry.path()).is_some() {
@@ -1186,6 +1192,68 @@ mod takeout_noise_tests {
}
}
+#[cfg(all(test, unix))]
+mod unfollowed_symlink_tests {
+ use super::walk_reporting;
+ use crate::ignore_rules::{IgnoreOptions, NOT_FOLLOWED_RULE};
+ use std::fs;
+ use std::os::unix::fs::symlink;
+
+ /// Default walk: links are omitted from the file list and named on the
+ /// report, once. `--follow-symlinks` indexes a target inside the folder
+ /// under the link's path and still refuses a target outside it.
+ #[test]
+ fn an_unfollowed_symlink_is_named_and_an_inside_target_is_indexed() {
+ let dir = tempfile::tempdir().unwrap();
+ let root = dir.path().join("proj");
+ fs::create_dir_all(root.join("src")).unwrap();
+ fs::write(root.join("src/lib.rs"), "fn alpha() {}\n").unwrap();
+ symlink("src/lib.rs", root.join("link-inside.rs")).unwrap();
+ let outside = dir.path().join("secret.txt");
+ fs::write(&outside, "secret").unwrap();
+ symlink(&outside, root.join("link-out.txt")).unwrap();
+
+ let (files, report) = walk_reporting(&root, false, IgnoreOptions::default()).unwrap();
+ let rels: Vec<&str> = files.iter().map(|e| e.rel.as_str()).collect();
+ assert!(rels.contains(&"src/lib.rs"), "{rels:?}");
+ assert!(
+ !rels.iter().any(|r| r.starts_with("link-")),
+ "unfollowed links must not be indexed: {rels:?}"
+ );
+ assert_eq!(
+ report.by_rule.get(NOT_FOLLOWED_RULE).map(|c| c.files),
+ Some(2),
+ "{report:?}"
+ );
+ let lines = report.summary_lines().join("\n");
+ assert_eq!(lines.matches("--follow-symlinks").count(), 1, "{lines}");
+ assert!(lines.contains(NOT_FOLLOWED_RULE), "{lines}");
+
+ let (followed, followed_report) =
+ walk_reporting(&root, true, IgnoreOptions::default()).unwrap();
+ let frels: Vec<&str> = followed.iter().map(|e| e.rel.as_str()).collect();
+ assert!(
+ frels.contains(&"link-inside.rs"),
+ "an inside target is indexed under the link path: {frels:?}"
+ );
+ assert!(
+ !frels.contains(&"link-out.txt"),
+ "a target outside the folder stays refused: {frels:?}"
+ );
+ assert!(
+ !followed_report.by_rule.contains_key(NOT_FOLLOWED_RULE),
+ "{followed_report:?}"
+ );
+ assert!(
+ followed_report
+ .summary_lines()
+ .iter()
+ .any(|l| l.contains("symlink:outside-root")),
+ "{followed_report:?}"
+ );
+ }
+}
+
#[cfg(test)]
mod portable_rel_tests {
use super::{portable_rel, walk_reporting};