规范get_relative_path名称

This commit is contained in:
mrbeanc
2023-12-30 16:51:22 +08:00
parent 1bb5332eaa
commit 642094cfca
4 changed files with 8 additions and 8 deletions

View File

@@ -51,7 +51,7 @@ fn add_a_file(file: &Path, index: &mut Index) {
return;
}
let rel_path = util::to_cur_relative_path(file);
let rel_path = util::get_relative_path(file);
if !file.exists() {
//文件被删除
index.remove(file);

View File

@@ -59,7 +59,7 @@ impl Changes {
[&mut change.new, &mut change.modified, &mut change.deleted]
.iter_mut()
.for_each(|paths| {
**paths = util::map(&**paths, |p| util::get_relative_path(p, &cur_dir));
**paths = util::map(&**paths, |p| util::get_relative_path_to_dir(p, &cur_dir));
});
change
}

View File

@@ -184,7 +184,7 @@ impl Index {
.entries
.iter()
.map(|(path, value)| {
let relative_path = util::get_relative_path(path, &self.working_dir);
let relative_path = util::get_relative_path_to_dir(path, &self.working_dir);
(relative_path, value.clone())
})
.collect();

View File

@@ -218,7 +218,7 @@ pub fn list_workdir_files() -> Vec<PathBuf> {
}
/// 获取相对于dir的 规范化 相对路径(不包含../ ./
pub fn get_relative_path(path: &Path, dir: &Path) -> PathBuf {
pub fn get_relative_path_to_dir(path: &Path, dir: &Path) -> PathBuf {
// 先统一为绝对路径
let abs_path = if path.is_relative() {
get_absolute_path(path)
@@ -253,12 +253,12 @@ pub fn get_common_dir(p1: &Path, p2: &Path) -> PathBuf {
/// 获取相较于工作区(Working Dir)的相对路径
pub fn to_workdir_relative_path(path: &Path) -> PathBuf {
get_relative_path(path, &get_working_dir().unwrap())
get_relative_path_to_dir(path, &get_working_dir().unwrap())
}
/// 获取相较于当前目录的 规范化 相对路径(不包含../ ./
pub fn to_cur_relative_path(path: &Path) -> PathBuf {
get_relative_path(path, &cur_dir())
pub fn get_relative_path(path: &Path) -> PathBuf {
get_relative_path_to_dir(path, &cur_dir())
}
/// 获取相较于工作区(Working Dir)的绝对路径
@@ -439,7 +439,7 @@ mod tests {
fn test_get_relative_path() {
test::setup_with_clean_mit();
let path = Path::new("../../src\\main.rs");
let rel_path = get_relative_path(&path, &cur_dir());
let rel_path = get_relative_path_to_dir(&path, &cur_dir());
println!("{:?}", rel_path);
assert_eq!(rel_path, path);