Skip to content

Instantly share code, notes, and snippets.

@yupferris
Last active November 4, 2017 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yupferris/5f67b654762826722d5bc0a8d8f3616d to your computer and use it in GitHub Desktop.
Save yupferris/5f67b654762826722d5bc0a8d8f3616d to your computer and use it in GitHub Desktop.
ffs windows, ruining my file watching with your case-insensitivity..
// This is kindof a crazy way to compare paths, and in certain unicode corner cases will not be entirely correct,
// but it's a workaround for file name case insensitivity on Windows and should be good enough for most cases.
// The general idea (matching path component suffixes) mimicks Rust's Path::ends_with.
fn ends_with_case_insensitive(path: &PathBuf, suffix: &PathBuf) -> bool {
let path_comps = path.components().map(|x| String::from(x.as_os_str().to_string_lossy()).to_lowercase()).rev();
let suffix_comps = suffix.components().map(|x| String::from(x.as_os_str().to_string_lossy()).to_lowercase()).rev();
let matching_suffix_pairs = path_comps.zip(suffix_comps).filter(|&(ref x, ref y)| x == y);
matching_suffix_pairs.count() == suffix.components().count()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment