Mercurial > hg > icedtea-web
changeset 1584:b60023d6a3a5
On windows, use dunce to canonicalize paths
* rust-launcher/Cargo.toml: added dunce crate for windows target
* rust-launcher/src/dirs_paths_helper.rs: declared canonicalize methods, one for windows, second for not-windows.
The windows one is using dunce, other is on PathBuf.
* rust-launcher/src/utils.rs:used above method insted PathBuf::canonicalize
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Wed, 06 Mar 2019 15:21:43 +0100 |
parents | c65cc4a88808 |
children | 2d7fe876a14c |
files | ChangeLog rust-launcher/Cargo.toml rust-launcher/src/dirs_paths_helper.rs rust-launcher/src/utils.rs |
diffstat | 4 files changed, 30 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Mar 05 16:18:51 2019 +0100 +++ b/ChangeLog Wed Mar 06 15:21:43 2019 +0100 @@ -1,3 +1,12 @@ +2019-03-06 Jiri Vanek <jvanek@redhat.com> + Lars Herschke <lhersch@dssgmbh.de> + + On windows, use dunce to canonicalize paths + * rust-launcher/Cargo.toml: added dunce crate for windows target + * rust-launcher/src/dirs_paths_helper.rs: declared canonicalize methods, one for windows, second for not-windows. + The windows one is using dunce, other is on PathBuf. + * rust-launcher/src/utils.rs:used above method insted PathBuf::canonicalize + 2019-03-05 Jiri Vanek <jvanek@redhat.com> Lars Herschke <lhersch@dssgmbh.de>
--- a/rust-launcher/Cargo.toml Tue Mar 05 16:18:51 2019 +0100 +++ b/rust-launcher/Cargo.toml Wed Mar 06 15:21:43 2019 +0100 @@ -4,5 +4,5 @@ authors = ["https://icedtea.classpath.org/wiki/IcedTea-Web"] [dependencies] - - +[target.'cfg(windows)'.dependencies] +dunce = "0.1.1"
--- a/rust-launcher/src/dirs_paths_helper.rs Tue Mar 05 16:18:51 2019 +0100 +++ b/rust-launcher/src/dirs_paths_helper.rs Wed Mar 06 15:21:43 2019 +0100 @@ -1,8 +1,12 @@ use os_access; use std; +use std::io; use std::env; +#[cfg(windows)] extern crate dunce; + + pub static ICEDTEA_WEB: &'static str = "icedtea-web"; pub static DEPLOYMENT_PROPERTIES: &'static str = "deployment.properties"; @@ -77,6 +81,18 @@ String::from(current_program().file_name().expect("unwrap of pgm name failed").to_str().expect("unwrap of pgm name failed")) } +#[cfg(not(windows))] +pub fn canonicalize(full_path: &std::path::PathBuf) -> Result<std::path::PathBuf, io::Error> { + full_path.canonicalize() +} + + +#[cfg(windows)] +pub fn canonicalize(full_path: &std::path::PathBuf) -> Result<std::path::PathBuf, io::Error> { + dunce::canonicalize(&full_path) +} + + /*tests*/ #[cfg(test)] mod tests {
--- a/rust-launcher/src/utils.rs Tue Mar 05 16:18:51 2019 +0100 +++ b/rust-launcher/src/utils.rs Wed Mar 06 15:21:43 2019 +0100 @@ -83,7 +83,7 @@ write!(&mut info1, "itw-rust-debug: trying {}", full_path.to_str().expect("unwrap failed")).expect("unwrap failed"); os.log(&info1); if dirs_paths_helper::is_file(&full_path) { - let can = match full_path.canonicalize() { + let can = match dirs_paths_helper::canonicalize(&full_path) { Ok(resolved) => { //.../bin/java resolved @@ -159,7 +159,7 @@ #[test] fn try_jre_exists_on_path() { - let top_dir = fake_jre(true).canonicalize().expect("canonicalize failed"); + let top_dir = dirs_paths_helper::canonicalize(&fake_jre(true)).expect("canonicalize failed"); let mut master_dir = top_dir.clone(); master_dir.push("bin"); let v1 = super::get_jdk_from_path_conditionally_testable(Some(fo::from(master_dir.clone())), hardcoded_paths::ItwLibSearch::DISTRIBUTION, &TestLogger::create_new()); @@ -196,7 +196,7 @@ let v3 = super::get_jdk_from_path_conditionally_testable(Some(fo::from(master_dir.clone())), hardcoded_paths::ItwLibSearch::BOTH, &TestLogger::create_new()); debuggable_remove_dir(&master_dir); assert_eq!(None, v1); - let parent = std::path::PathBuf::from(master_dir.parent().expect("just created")).canonicalize().expect("canonicalize failed"); + let parent = dirs_paths_helper::canonicalize(&std::path::PathBuf::from(master_dir.parent().expect("just created"))).expect("canonicalize failed"); assert_eq!(Some(parent.clone()), v2); assert_eq!(Some(parent.clone()), v3); }