-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Fixed resume matching to respect case insensitivity when using WSL mount points #8000
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
Merged
+133
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
35c27e7
Fixed resume matching to respect case insensitivity when using WSL mo…
etraut-openai 4da32d5
Renamed canonicalize to normalize_for_path_comparison
etraut-openai 565fa20
Updated test to avoid calling unsafe `set_var`.
etraut-openai fa0dc68
Fix clippy issue
etraut-openai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| use std::path::Path; | ||
| use std::path::PathBuf; | ||
|
|
||
| use crate::env; | ||
|
|
||
| pub fn normalize_for_path_comparison(path: &Path) -> std::io::Result<PathBuf> { | ||
| let canonical = path.canonicalize()?; | ||
| Ok(normalize_for_wsl(canonical)) | ||
| } | ||
|
|
||
| fn normalize_for_wsl(path: PathBuf) -> PathBuf { | ||
| normalize_for_wsl_with_flag(path, env::is_wsl()) | ||
| } | ||
|
|
||
| fn normalize_for_wsl_with_flag(path: PathBuf, is_wsl: bool) -> PathBuf { | ||
| if !is_wsl { | ||
| return path; | ||
| } | ||
|
|
||
| if !is_wsl_case_insensitive_path(&path) { | ||
| return path; | ||
| } | ||
|
|
||
| lower_ascii_path(path) | ||
| } | ||
|
|
||
| fn is_wsl_case_insensitive_path(path: &Path) -> bool { | ||
| #[cfg(target_os = "linux")] | ||
| { | ||
| use std::os::unix::ffi::OsStrExt; | ||
| use std::path::Component; | ||
|
|
||
| let mut components = path.components(); | ||
| let Some(Component::RootDir) = components.next() else { | ||
| return false; | ||
| }; | ||
| let Some(Component::Normal(mnt)) = components.next() else { | ||
| return false; | ||
| }; | ||
| if !ascii_eq_ignore_case(mnt.as_bytes(), b"mnt") { | ||
| return false; | ||
| } | ||
| let Some(Component::Normal(drive)) = components.next() else { | ||
| return false; | ||
| }; | ||
| let drive_bytes = drive.as_bytes(); | ||
| drive_bytes.len() == 1 && drive_bytes[0].is_ascii_alphabetic() | ||
| } | ||
| #[cfg(not(target_os = "linux"))] | ||
| { | ||
| let _ = path; | ||
| false | ||
| } | ||
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| fn ascii_eq_ignore_case(left: &[u8], right: &[u8]) -> bool { | ||
| left.len() == right.len() | ||
| && left | ||
| .iter() | ||
| .zip(right) | ||
| .all(|(lhs, rhs)| lhs.to_ascii_lowercase() == *rhs) | ||
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| fn lower_ascii_path(path: PathBuf) -> PathBuf { | ||
| use std::ffi::OsString; | ||
| use std::os::unix::ffi::OsStrExt; | ||
| use std::os::unix::ffi::OsStringExt; | ||
|
|
||
| // WSL mounts Windows drives under /mnt/<drive>, which are case-insensitive. | ||
| let bytes = path.as_os_str().as_bytes(); | ||
| let mut lowered = Vec::with_capacity(bytes.len()); | ||
| for byte in bytes { | ||
| lowered.push(byte.to_ascii_lowercase()); | ||
| } | ||
| PathBuf::from(OsString::from_vec(lowered)) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn lower_ascii_path(path: PathBuf) -> PathBuf { | ||
| path | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| #[cfg(target_os = "linux")] | ||
| mod wsl { | ||
| use super::super::normalize_for_wsl_with_flag; | ||
| use pretty_assertions::assert_eq; | ||
| use std::path::PathBuf; | ||
|
|
||
| #[test] | ||
| fn wsl_mnt_drive_paths_lowercase() { | ||
| let normalized = normalize_for_wsl_with_flag(PathBuf::from("/mnt/C/Users/Dev"), true); | ||
|
|
||
| assert_eq!(normalized, PathBuf::from("/mnt/c/users/dev")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn wsl_non_drive_paths_unchanged() { | ||
| let path = PathBuf::from("/mnt/cc/Users/Dev"); | ||
| let normalized = normalize_for_wsl_with_flag(path.clone(), true); | ||
|
|
||
| assert_eq!(normalized, path); | ||
| } | ||
|
|
||
| #[test] | ||
| fn wsl_non_mnt_paths_unchanged() { | ||
| let path = PathBuf::from("/home/Dev"); | ||
| let normalized = normalize_for_wsl_with_flag(path.clone(), true); | ||
|
|
||
| assert_eq!(normalized, path); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.