This commit is contained in:
Azalea Colburn 2025-08-08 10:56:37 +02:00 committed by GitHub
commit d133e7c598
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 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>> { fn get_stream<'a>(&self, db: &'a mut Database, now: Epoch) -> Result<Stream<'a>> {
let mut options = StreamOptions::new(now) let mut options = StreamOptions::new(now)
.with_keywords(self.keywords.iter().map(|s| s.as_str())) .with_keywords(self.transformed_keywords())
.with_exclude(config::exclude_dirs()?); .with_exclude(config::exclude_dirs()?);
if !self.all { if !self.all {
let resolve_symlinks = config::resolve_symlinks(); let resolve_symlinks = config::resolve_symlinks();
@ -117,4 +117,23 @@ impl Query {
} }
.spawn() .spawn()
} }
/// ## Returns
/// `self.keywords` with file paths transformed into
/// their parent directory paths, directory paths unchanged
///
/// ## Notes
/// - Heap allocates an iterator of Strings with length of self.keywords
/// - Only uses sans-IO Path methods
fn transformed_keywords(&self) -> impl Iterator<Item = String> + use<'_> {
self.keywords.iter().map(|keyword| {
let path = std::path::Path::new(keyword);
match path.parent() {
None => keyword,
Some(path) if path.to_str() == Some("") => keyword,
Some(path) => path.to_str().unwrap(),
}
.to_string()
})
}
} }

View File

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