mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-16 10:49:13 +00:00
update
This commit is contained in:
25
libmarlin/src/utils.rs
Normal file
25
libmarlin/src/utils.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
//! Misc shared helpers.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Determine a filesystem root to limit recursive walking on glob scans.
|
||||
pub fn determine_scan_root(pattern: &str) -> PathBuf {
|
||||
let first_wild = pattern
|
||||
.find(|c| matches!(c, '*' | '?' | '['))
|
||||
.unwrap_or(pattern.len());
|
||||
let mut root = PathBuf::from(&pattern[..first_wild]);
|
||||
|
||||
while root
|
||||
.as_os_str()
|
||||
.to_string_lossy()
|
||||
.contains(|c| matches!(c, '*' | '?' | '['))
|
||||
{
|
||||
root = root.parent().map(|p| p.to_path_buf()).unwrap_or_default();
|
||||
}
|
||||
|
||||
if root.as_os_str().is_empty() {
|
||||
PathBuf::from(".")
|
||||
} else {
|
||||
root
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user