diff options
Diffstat (limited to 'src-tauri/src/utils/path.rs')
| -rw-r--r-- | src-tauri/src/utils/path.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src-tauri/src/utils/path.rs b/src-tauri/src/utils/path.rs index deaebb5..1db6e5b 100644 --- a/src-tauri/src/utils/path.rs +++ b/src-tauri/src/utils/path.rs @@ -59,7 +59,7 @@ pub fn normalize_java_path(java_path: &str) -> Result<PathBuf, String> { } } } - + // If still not found after PATH search, return specific error if !path.exists() { return Err( @@ -80,7 +80,7 @@ pub fn normalize_java_path(java_path: &str) -> Result<PathBuf, String> { // Canonicalize and strip UNC prefix for clean path let canonical = std::fs::canonicalize(&path) .map_err(|e| format!("Failed to resolve Java path '{}': {}", path.display(), e))?; - + Ok(strip_unc_prefix(canonical)) } @@ -98,7 +98,7 @@ pub fn normalize_java_path(java_path: &str) -> Result<PathBuf, String> { } } } - + // If still not found after PATH search, return specific error if !path.exists() { return Err( @@ -119,7 +119,7 @@ pub fn normalize_java_path(java_path: &str) -> Result<PathBuf, String> { // Canonicalize to resolve symlinks and get absolute path let canonical = std::fs::canonicalize(&path) .map_err(|e| format!("Failed to resolve Java path '{}': {}", path.display(), e))?; - + Ok(strip_unc_prefix(canonical)) } @@ -196,23 +196,23 @@ mod tests { fn test_normalize_with_temp_file() { // Create a temporary file to test with an actual existing path let temp_dir = std::env::temp_dir(); - + #[cfg(target_os = "windows")] let temp_file = temp_dir.join("test_java_normalize.exe"); #[cfg(not(target_os = "windows"))] let temp_file = temp_dir.join("test_java_normalize"); - + // Create the file if let Ok(mut file) = fs::File::create(&temp_file) { let _ = file.write_all(b"#!/bin/sh\necho test"); drop(file); - + // Test normalization let result = normalize_java_path(temp_file.to_str().unwrap()); - + // Clean up let _ = fs::remove_file(&temp_file); - + // Verify result assert!(result.is_ok(), "Failed to normalize temp file path"); let normalized = result.unwrap(); @@ -227,12 +227,12 @@ mod tests { let unc_path = PathBuf::from(r"\\?\C:\Windows\System32\cmd.exe"); let stripped = strip_unc_prefix(unc_path); assert_eq!(stripped.to_string_lossy(), r"C:\Windows\System32\cmd.exe"); - + let normal_path = PathBuf::from(r"C:\Windows\System32\cmd.exe"); let unchanged = strip_unc_prefix(normal_path.clone()); assert_eq!(unchanged, normal_path); } - + #[cfg(not(target_os = "windows"))] { let path = PathBuf::from("/usr/bin/java"); |