sigoden / dufs

A file server that supports static serving, uploading, searching, accessing control, webdav...
Other
6.12k stars 305 forks source link

Hide content by Regex pattern instead of Wildcard pattern #410

Closed zhus closed 3 months ago

zhus commented 3 months ago

Specific Demand

Hi!

Wildcards has very limited capabilities so would be useful to use regex patterns instead. Unfortunately I extreamly novice in Rust lang and not a professional programmer at all, don't know how to suggest patches to project, but after "cargo add regex" my implementation builds good and server works and filters patterns as expected.

And may be you can help me in one specific problem -- how to prevent listing of root of server, but keep list files in subfolders?

Implement Suggestion

replace in utils.rs

pub fn glob(pattern: &str, target: &str) -> bool {
    let pat = match ::glob::Pattern::new(pattern) {
        Ok(pat) => pat,
        Err(_) => return false,
    };
    pat.matches(target)
}

to

pub fn glob(pattern: &str, target: &str) -> bool {
    let rex = match ::regex::Regex::new(pattern) {
        Ok(rex) => rex,
        Err(_) => return false,
    };
    rex.is_match(target)
}
sigoden commented 3 months ago

We will not support this feature.

Glob patterns are more mature for matching paths, which explains why they are widely used in ignore files.

Furthermore, tens of thousands of users are already accustomed to using globs as the value ofhidden. You can't just change that on a whim.