File paths are transformed into parent directory paths

This commit is contained in:
Azalea Colburn 2025-03-14 20:59:39 -07:00
parent 2ecb310108
commit 1f6e9ecf51
No known key found for this signature in database
2 changed files with 20 additions and 4 deletions

View File

@ -78,7 +78,7 @@ impl Query {
fn get_stream<'a>(&self, db: &'a mut Database, now: Epoch) -> Result<Stream<'a>> {
let mut options = StreamOptions::new(now)
.with_keywords(self.keywords.iter().map(|s| s.as_str()))
.with_keywords(self.transfomed_keywords())
.with_exclude(config::exclude_dirs()?);
if !self.all {
let resolve_symlinks = config::resolve_symlinks();
@ -117,4 +117,20 @@ impl Query {
}
.spawn()
}
/// ## Returns
/// `self.keywords` with file paths transformed into their parent directory paths and directory paths unchanged
///
/// ## Warning
/// Clones self.keywords
fn transfomed_keywords(&self) -> impl Iterator<Item = String> + use<'_> {
self.keywords.iter().map(|keyword| {
if !std::path::Path::new(keyword).is_dir() {
let dirs: Vec<&str> = keyword.split("/").collect();
dirs.split_last().unwrap().1.join("/").to_string()
} else {
keyword.to_string()
}
})
}
}

View File

@ -48,16 +48,16 @@ impl<'a> Stream<'a> {
}
fn filter_by_keywords(&self, path: &str) -> bool {
let (keywords_last, keywords) = match self.options.keywords.split_last() {
let (last_keyword, keywords) = match self.options.keywords.split_last() {
Some(split) => split,
None => return true,
};
let path = util::to_lowercase(path);
let mut path = path.as_str();
match path.rfind(keywords_last) {
match path.rfind(last_keyword) {
Some(idx) => {
if path[idx + keywords_last.len()..].contains(path::is_separator) {
if path[idx + last_keyword.len()..].contains(path::is_separator) {
return false;
}
path = &path[..idx];