From a5014a912497bd62e32c90f40721854061c3936e Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 5 Jun 2024 21:52:54 +1000 Subject: [PATCH] Better name --- crates/pet-conda/src/environment_locations.rs | 8 ++++---- crates/pet-conda/src/environments.rs | 6 +++--- crates/pet-utils/src/path.rs | 6 +++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/pet-conda/src/environment_locations.rs b/crates/pet-conda/src/environment_locations.rs index a542dcae..88ccccdf 100644 --- a/crates/pet-conda/src/environment_locations.rs +++ b/crates/pet-conda/src/environment_locations.rs @@ -7,7 +7,7 @@ use crate::{ utils::{is_conda_env, is_conda_install}, }; use log::trace; -use pet_utils::path::get_absolute_path; +use pet_utils::path::fix_file_path_casing; use std::{ fs, path::{Path, PathBuf}, @@ -146,7 +146,7 @@ pub fn get_conda_envs_from_environment_txt(env_vars: &EnvVariables) -> Vec Vec Vec { - use pet_utils::path::get_absolute_path; + use pet_utils::path::fix_file_path_casing; let user_profile = env_vars.userprofile.clone().unwrap_or_default(); let program_data = env_vars.programdata.clone().unwrap_or_default(); @@ -209,7 +209,7 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec Option { // The casing in history might not be same as that on disc // We do not want to have duplicates in different cases. // & we'd like to preserve the case of the original path as on disc. - return Some(get_absolute_path(conda_dir).to_path_buf()); + return Some(fix_file_path_casing(conda_dir).to_path_buf()); } } // Sometimes we can have paths like @@ -212,7 +212,7 @@ fn get_conda_dir_from_cmd(cmd_line: String) -> Option { // The casing in history might not be same as that on disc // We do not want to have duplicates in different cases. // & we'd like to preserve the case of the original path as on disc. - return Some(get_absolute_path(&cmd_line).to_path_buf()); + return Some(fix_file_path_casing(&cmd_line).to_path_buf()); } } None diff --git a/crates/pet-utils/src/path.rs b/crates/pet-utils/src/path.rs index f0dba71a..5485929c 100644 --- a/crates/pet-utils/src/path.rs +++ b/crates/pet-utils/src/path.rs @@ -6,7 +6,11 @@ use std::{ path::{Path, PathBuf}, }; -pub fn get_absolute_path(path: &Path) -> PathBuf { +// This function is used to fix the casing of the file path. +// by returning the actual path with the correct casing as found on the OS. +// This is a noop for Unix systems. +// I.e. this function is only useful on Windows. +pub fn fix_file_path_casing(path: &Path) -> PathBuf { // Return the path as is. if cfg!(unix) { return path.to_path_buf();