Skip to content

Commit 5c040de

Browse files
committed
normpath
1 parent a8ac1df commit 5c040de

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CHANGELOG-rust.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This changelog tracks the Rust `svdtools` project. See
66
## [Unreleased]
77

88
* cluster add/modify
9+
* use `normpath` instead of std::fs::canonicalize
910

1011
## [v0.2.8] 2022-01-28
1112

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ globset = "0.4.8"
4141
commands = "0.0.5"
4242
env_logger = "0.9"
4343
log = { version = "~0.4", features = ["std"] }
44+
normpath = "1.1.0"
4445

4546
[dev-dependencies]
4647
tempfile = "3.3"

src/patch/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use svd_parser::SVDError::DimIndexParse;
1515
use svd_rs::{DimElement, DimElementBuilder, MaybeArray};
1616
use yaml_rust::{yaml::Hash, Yaml, YamlLoader};
1717

18-
use anyhow::{anyhow, Context, Ok, Result};
18+
use anyhow::{anyhow, Context, Result};
1919
pub type PatchResult = anyhow::Result<()>;
2020

2121
mod device;
@@ -72,7 +72,14 @@ pub fn process_file(yaml_file: &Path) -> Result<()> {
7272

7373
/// Gets the absolute path of relpath from the point of view of frompath.
7474
fn abspath(frompath: &Path, relpath: &Path) -> Result<PathBuf, std::io::Error> {
75-
std::fs::canonicalize(frompath.parent().unwrap().join(relpath))
75+
normpath::BasePath::new(frompath)
76+
.unwrap()
77+
.parent()
78+
.unwrap()
79+
.unwrap()
80+
.join(relpath)
81+
.canonicalize()
82+
.map(|b| b.as_path().into())
7683
}
7784

7885
/// Recursively loads any included YAML files.

src/test_utils.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,14 @@ pub fn get_patcher(test_subdir: &Path) -> Result<(Device, Hash)> {
3939

4040
/// Gets the absolute path of relpath from the point of view of frompath.
4141
fn abspath(frompath: &Path, relpath: &Path) -> PathBuf {
42-
std::fs::canonicalize(frompath.parent().unwrap().join(relpath)).unwrap()
42+
normpath::BasePath::new(frompath)
43+
.unwrap()
44+
.parent()
45+
.unwrap()
46+
.unwrap()
47+
.join(relpath)
48+
.canonicalize()
49+
.unwrap()
50+
.as_path()
51+
.into()
4352
}

0 commit comments

Comments
 (0)