mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 11:33:23 +02:00
some param name, variable name refine
This commit is contained in:
@ -45,9 +45,9 @@ pub mod singleton {
|
|||||||
/// set_pwd_per_drive
|
/// set_pwd_per_drive
|
||||||
/// Record PWD for drive, path must be absolute path
|
/// Record PWD for drive, path must be absolute path
|
||||||
/// return Ok(()) if succeeded, otherwise error message
|
/// return Ok(()) if succeeded, otherwise error message
|
||||||
pub fn set_pwd(_path: &Path) -> Result<(), PathError> {
|
pub fn set_pwd(path: &Path) -> Result<(), PathError> {
|
||||||
if let Ok(mut pwd_per_drive) = get_drive_pwd_map().lock() {
|
if let Ok(mut pwd_per_drive) = get_drive_pwd_map().lock() {
|
||||||
pwd_per_drive.set_pwd(_path)
|
pwd_per_drive.set_pwd(path)
|
||||||
} else {
|
} else {
|
||||||
Err(CantLockSharedMap)
|
Err(CantLockSharedMap)
|
||||||
}
|
}
|
||||||
@ -56,10 +56,10 @@ pub mod singleton {
|
|||||||
/// expand_pwe_per_drive
|
/// expand_pwe_per_drive
|
||||||
/// Input relative path, expand PWD-per-drive to construct absolute path
|
/// Input relative path, expand PWD-per-drive to construct absolute path
|
||||||
/// return PathBuf for absolute path, None if input path is invalid.
|
/// return PathBuf for absolute path, None if input path is invalid.
|
||||||
pub fn expand_pwd(_path: &Path) -> Option<PathBuf> {
|
pub fn expand_pwd(path: &Path) -> Option<PathBuf> {
|
||||||
if need_expand_pwd_per_drive(_path) {
|
if need_expand_pwd_per_drive(path) {
|
||||||
if let Ok(mut pwd_per_drive) = get_drive_pwd_map().lock() {
|
if let Ok(mut pwd_per_drive) = get_drive_pwd_map().lock() {
|
||||||
return pwd_per_drive.expand_path(_path);
|
return pwd_per_drive.expand_path(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
@ -68,8 +68,8 @@ pub mod singleton {
|
|||||||
|
|
||||||
/// Helper to check if input path is relative path
|
/// Helper to check if input path is relative path
|
||||||
/// with drive letter, it can be expanded with PWD-per-drive.
|
/// with drive letter, it can be expanded with PWD-per-drive.
|
||||||
fn need_expand_pwd_per_drive(_path: &Path) -> bool {
|
fn need_expand_pwd_per_drive(path: &Path) -> bool {
|
||||||
if let Some(path_str) = _path.to_str() {
|
if let Some(path_str) = path.to_str() {
|
||||||
let chars: Vec<char> = path_str.chars().collect();
|
let chars: Vec<char> = path_str.chars().collect();
|
||||||
if chars.len() >= 2 {
|
if chars.len() >= 2 {
|
||||||
return chars[1] == ':' && (chars.len() == 2 || (chars[2] != '/' && chars[2] != '\\'));
|
return chars[1] == ':' && (chars.len() == 2 || (chars[2] != '/' && chars[2] != '\\'));
|
||||||
@ -135,8 +135,8 @@ impl DriveToPwdMap {
|
|||||||
match c.next() {
|
match c.next() {
|
||||||
None => Err(PathError::InvalidDriveLetter),
|
None => Err(PathError::InvalidDriveLetter),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
self.map[drive_letter as usize - 'A' as usize] =
|
let drive_index = drive_letter as usize - 'A' as usize;
|
||||||
Some(drive_letter.to_string() + c.as_str());
|
self.map[drive_index] = Some(drive_letter.to_string() + c.as_str());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,16 +150,16 @@ impl DriveToPwdMap {
|
|||||||
|
|
||||||
/// Get the PWD for drive, if not yet, ask GetFullPathNameW(),
|
/// Get the PWD for drive, if not yet, ask GetFullPathNameW(),
|
||||||
/// or else return default r"X:\".
|
/// or else return default r"X:\".
|
||||||
fn get_pwd(&mut self, drive: char) -> Result<String, PathError> {
|
fn get_pwd(&mut self, drive_letter: char) -> Result<String, PathError> {
|
||||||
if drive.is_ascii_alphabetic() {
|
if drive_letter.is_ascii_alphabetic() {
|
||||||
let drive = drive.to_ascii_uppercase();
|
let drive_letter = drive_letter.to_ascii_uppercase();
|
||||||
let index = drive as usize - 'A' as usize;
|
let drive_index = drive_letter as usize - 'A' as usize;
|
||||||
Ok(self.map[index].clone().unwrap_or_else(|| {
|
Ok(self.map[drive_index].clone().unwrap_or_else(|| {
|
||||||
if let Some(sys_pwd) = get_full_path_name_w(&format!("{}:", drive)) {
|
if let Some(sys_pwd) = get_full_path_name_w(&format!("{}:", drive_letter)) {
|
||||||
self.map[index] = Some(sys_pwd.clone());
|
self.map[drive_index] = Some(sys_pwd.clone());
|
||||||
sys_pwd
|
sys_pwd
|
||||||
} else {
|
} else {
|
||||||
format!(r"{}:\", drive)
|
format!(r"{}:\", drive_letter)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user