feature/improve-memories-exclude #42
@@ -242,25 +242,52 @@ pub async fn list_memories(
|
|||||||
|
|
||||||
let base = Path::new(&app_state.base_path);
|
let base = Path::new(&app_state.base_path);
|
||||||
|
|
||||||
// Build a list of excluded directories with full paths
|
// Build a list of excluded directories and patterns, all scoped under base:
|
||||||
let excluded_paths: Vec<PathBuf> = app_state
|
// - entries starting with '/' are treated as absolute *under base* (e.g. "/foo/bar" -> base/foo/bar)
|
||||||
.excluded_dirs
|
// - entries without '/' are treated as substring patterns matched anywhere in the path
|
||||||
.iter()
|
let mut excluded_dirs: Vec<PathBuf> = Vec::new();
|
||||||
.map(|dir| base.join(dir))
|
let mut excluded_patterns: Vec<String> = Vec::new();
|
||||||
.collect();
|
|
||||||
|
|
||||||
debug!("Excluded directories: {:?}", excluded_paths);
|
for dir in &app_state.excluded_dirs {
|
||||||
|
if dir.starts_with('/') {
|
||||||
|
// "Absolute under base": strip leading '/' and join with base
|
||||||
|
let rel = &dir[1..];
|
||||||
|
if !rel.is_empty() {
|
||||||
|
excluded_dirs.push(base.join(rel));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Pure pattern (no '/'): match as substring anywhere in the path
|
||||||
|
excluded_patterns.push(dir.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug!("Excluded directories (under base): {:?}", excluded_dirs);
|
||||||
|
debug!("Excluded path patterns: {:?}", excluded_patterns);
|
||||||
|
|
||||||
let entries: Vec<_> = WalkDir::new(base)
|
let entries: Vec<_> = WalkDir::new(base)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
.filter(|e| {
|
.filter(|e| {
|
||||||
// Skip excluded directories
|
|
||||||
if !excluded_paths.is_empty() {
|
|
||||||
let path = e.path();
|
let path = e.path();
|
||||||
for excluded in &excluded_paths {
|
|
||||||
|
// Skip excluded directories (all are under base)
|
||||||
|
if !excluded_dirs.is_empty() {
|
||||||
|
for excluded in &excluded_dirs {
|
||||||
if path.starts_with(excluded) {
|
if path.starts_with(excluded) {
|
||||||
debug!("Skipping excluded path: {:?}", path);
|
debug!("Skipping excluded dir path: {:?}", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip paths that match any of the relative patterns (substring match under base)
|
||||||
|
if !excluded_patterns.is_empty() {
|
||||||
|
if let Some(path_str) = path.to_str() {
|
||||||
|
if excluded_patterns.iter().any(|pat| path_str.contains(pat)) {
|
||||||
|
debug!(
|
||||||
|
"Skipping excluded pattern match: {:?} (patterns: {:?})",
|
||||||
|
path, excluded_patterns
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user