Skip to content

Commit

Permalink
fix: Fixed relative paths resolve on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Apr 18, 2023
1 parent 2c2d693 commit 22b0816
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Changelog

- [Changelog](#changelog)
- [0.1.4](#014)
- [0.1.3](#013)
- [0.1.2](#012)
- [0.1.1](#011)
- [0.1.0](#010)

---

## 0.1.4

Released on 18/04/2023

- Fixed relative paths resolve on Windows

## 0.1.3

Released on 10/02/2023
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT"
name = "remotefs-ssh"
readme = "README.md"
repository = "https://github.com/veeso/remotefs-rs-ssh"
version = "0.1.3"
version = "0.1.4"

[dependencies]
chrono = "^0.4.19"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<p align="center">~ Remotefs SSH client ~</p>

<p align="center">Developed by <a href="https://veeso.github.io/" target="_blank">@veeso</a></p>
<p align="center">Current version: 0.1.3 (10/02/2023)</p>
<p align="center">Current version: 0.1.4 (18/04/2023)</p>

<p align="center">
<a href="https://opensource.org/licenses/MIT"
Expand Down
18 changes: 18 additions & 0 deletions src/ssh/scp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,24 @@ mod test {
finalize_client(client);
}

#[test]
#[cfg(feature = "with-containers")]
#[serial]
fn should_change_directory_relative() {
crate::mock::logger();
let mut client = setup_client();
assert!(client
.create_dir(
Path::new("should_change_directory_relative"),
UnixPex::from(0o755)
)
.is_ok());
assert!(client
.change_dir(Path::new("should_change_directory_relative/"))
.is_ok());
finalize_client(client);
}

#[test]
#[cfg(feature = "with-containers")]
#[serial]
Expand Down
15 changes: 14 additions & 1 deletion src/utils/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,25 @@ pub fn absolutize(wrkdir: &Path, target: &Path) -> PathBuf {
true => target.to_path_buf(),
false => {
let mut p: PathBuf = wrkdir.to_path_buf();
p.push(target);
let fixed_path = resolve(target);
p.push(fixed_path);
p
}
}
}

/// Fix provided path; on Windows fixes the backslashes, converting them to slashes
/// While on POSIX does nothing
#[cfg(target_os = "windows")]
fn resolve(p: &Path) -> PathBuf {
PathBuf::from(path_slash::PathExt::to_slash_lossy(p).as_str())
}

#[cfg(target_family = "unix")]
fn resolve(p: &Path) -> PathBuf {
p.to_path_buf()
}

#[cfg(test)]
mod test {

Expand Down

0 comments on commit 22b0816

Please sign in to comment.