Skip to content

glob-tilde-expansion #149 #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

BiswajitThakur
Copy link

  • Adding new field to MatchOptions struct, the test is faild. could i update or add new test or any changes let me know.

Co-authored-by: Rene Leonhardt <[email protected]>
src/lib.rs Outdated
Comment on lines 1134 to 1138
/// Enables or disables tilde (`~`) expansion in glob patterns
pub fn glob_tilde_expansion(mut self, v: bool) -> Self {
self.glob_tilde_expansion = v;
self
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really have a builder pattern here, so this isn't needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will remove it.

_ => {}
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intent of this branch? AFAIK ~foo without the path shouldn't be a valid pattern

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ~ followed by user name then ~ and username are substituted by the home directory of that user.
  • If the username is invalid, or the home directory cannot be determined, then no substitution is performed.
  • if we want ~ followed by not username or not / or the home directory cannot be determined as an error. we have to add a another field to MatchOptions. if the fiend is set true the it will be return error. if the field set false, it ignore it.

(could i add an extra field to the MatcherOptiond ?)

https://man7.org/linux/man-pages/man3/glob.3.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that in the glob manpage, thanks.

I think we should defer that part, and error if there is ~ not followed by /. Checking the env isn't always accurate: it needs getpwuid_r on Unix and GetUserProfileDirectoryA on Windows, which is more complexity than this crate should add.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, i will update it.

Co-authored-by: Rene Leonhardt <[email protected]>
src/utils.rs Outdated
Comment on lines 10 to 13
#[cfg(not(target_os = "windows"))]
return std::env::var("USER").ok();
#[cfg(target_os = "windows")]
std::env::var("USERNAME").ok()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will go away with #173 (comment) but for future reference, you should use cfg! rather than #[cfg(...)] where possible (i.e. when the types are the same).

let varname = if cfg!(windows) { "USERNAME" } else { "USER" };
env::var(varname).ok()

Makes no difference here but in general it avoids conditional compilation, so both branches get checked on all platforms. Also lets you use else.

Copy link

@reneleonhardt reneleonhardt Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, and even the merciless rust formatter doesn't bloat 1 line to 5 lines in this case at least 😍

env::var(if cfg!(windows) { "USERNAME" } else { "USER" }).ok()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants