Mercurial > hg > release > icedtea-web-1.8
changeset 1530:99b77a265f54
Made get_home os dependent.
* rust-launcher/src/dirs_paths_helper.rs: removed get_home; used os.get_home where appropriate. Introduced is_dir, and moved is_file here and theirs tests.
* rust-launcher/src/os_access.rs: prescribed get_home and implemeted for Linux, solemnly on HOME variable
* rust-launcher/src/property_from_file.rs: adapted to new location of is_file
* rust-launcher/src/property_from_files_resolver.rs: implemented get_home doing nothing for testing stub
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Mon, 10 Dec 2018 14:44:28 +0100 |
parents | 9bac379fb97e |
children | d6d1652a1837 |
files | ChangeLog rust-launcher/src/dirs_paths_helper.rs rust-launcher/src/os_access.rs rust-launcher/src/property_from_file.rs rust-launcher/src/property_from_files_resolver.rs |
diffstat | 5 files changed, 106 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Nov 30 19:12:09 2018 +0100 +++ b/ChangeLog Mon Dec 10 14:44:28 2018 +0100 @@ -1,3 +1,12 @@ +2018-12-10 Jiri Vanek <jvanek@redhat.com> + + Made get_home os dependent. + * rust-launcher/src/dirs_paths_helper.rs: removed get_home; used os.get_home where appropriate. + Introduced is_dir, and moved is_file here and theirs tests. + * rust-launcher/src/os_access.rs: prescribed get_home and implemeted for Linux, solemnly on HOME variable + * rust-launcher/src/property_from_file.rs: adapted to new location of is_file + * rust-launcher/src/property_from_files_resolver.rs: implemented get_home doing nothing for testing stub + 2018-11-30 Jiri Vanek <jvanek@redhat.com> verbose also from deployment.properties
--- a/rust-launcher/src/dirs_paths_helper.rs Fri Nov 30 19:12:09 2018 +0100 +++ b/rust-launcher/src/dirs_paths_helper.rs Mon Dec 10 14:44:28 2018 +0100 @@ -6,20 +6,14 @@ pub static ICEDTEA_WEB: &'static str = "icedtea-web"; pub static DEPLOYMENT_PROPERTIES: &'static str = "deployment.properties"; -pub fn get_home() -> Option<std::path::PathBuf> { - match env::home_dir() { - Some(p) => Some(p), - None => None - } -} -pub fn get_xdg_config_dir() -> Option<std::path::PathBuf> { +pub fn get_xdg_config_dir(os: &os_access::Os) -> Option<std::path::PathBuf> { match env::var("XDG_CONFIG_HOME") { Ok(war) => { Some(std::path::PathBuf::from(war)) } Err(_) => { - match get_home() { + match os.get_home() { Some(mut p) => { p.push(".config"); Some(p) @@ -58,11 +52,21 @@ append_deployment_file(os.get_system_config_javadir()) } +pub fn is_file(path: &std::path::PathBuf) -> bool { + path.metadata().map(|md| md.is_file()).unwrap_or(false) +} + +pub fn is_dir(path: &std::path::PathBuf) -> bool { + path.metadata().map(|md| md.is_dir()).unwrap_or(false) +} /*tests*/ #[cfg(test)] mod tests { + use std; + use std::fs; use os_access; + use utils::tests_utils as tu; #[test] fn check_config_files_paths() { @@ -92,4 +96,52 @@ assert_eq!(true, p5.clone().expect("unwrap failed").display().to_string().contains("deployment")); assert_eq!(true, p6.clone().expect("unwrap failed").display().to_string().ends_with("deployment.properties")); } + + #[test] + fn is_not_file() { + let r = super::is_file(&std::path::PathBuf::from("/definitely/not/existing/file")); + assert_eq!(false, r); + } + + #[test] + fn is_not_file_is_dir() { + let dir = tu::create_tmp_file(); + tu::debuggable_remove_file(&dir); + let _cd = fs::create_dir(&dir); //silenting compiler worning + let r = super::is_file(&dir); + tu::debuggable_remove_dir(&dir); + assert_eq!(false, r); + } + + #[test] + fn is_file() { + let file = tu::create_tmp_file(); + let r = super::is_file(&file); + tu::debuggable_remove_file(&file); + assert_eq!(true, r); + } + + #[test] + fn is_not_dir() { + let r = super::is_dir(&std::path::PathBuf::from("/definitely/not/existing/file")); + assert_eq!(false, r); + } + + #[test] + fn is_dir() { + let dir = tu::create_tmp_file(); + tu::debuggable_remove_file(&dir); + let _cd = fs::create_dir(&dir); //silenting compiler worning + let r = super::is_dir(&dir); + tu::debuggable_remove_dir(&dir); + assert_eq!(true, r); + } + + #[test] + fn is_not_dir_is_file() { + let file = tu::create_tmp_file(); + let r = super::is_dir(&file); + tu::debuggable_remove_file(&file); + assert_eq!(false, r); + } }
--- a/rust-launcher/src/os_access.rs Fri Nov 30 19:12:09 2018 +0100 +++ b/rust-launcher/src/os_access.rs Mon Dec 10 14:44:28 2018 +0100 @@ -1,20 +1,25 @@ use std; use dirs_paths_helper; +use std::env; pub trait Os { - //logging "api" can change + // logging "api" can change fn log(&self, s: &str); fn info(&self, s: &str); fn get_registry_jdk(&self) -> Option<std::path::PathBuf>; // next to system and home cfg dir, there is also by-jre config dir, but that do not need to be handled os-specific way - //https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/jcp/properties.html + // https://docs.oracle.com/javase/7/docs/technotes/guides/jweb/jcp/properties.html fn get_system_config_javadir(&self) -> Option<std::path::PathBuf>; fn get_user_config_dir(&self) -> Option<std::path::PathBuf>; - //is valid only on linux, otherwise returns get_system_config_javadir + // is valid only on linux, otherwise returns get_system_config_javadir fn get_legacy_system_config_javadir(&self) -> Option<std::path::PathBuf>; - //is valid only on linux, otherwise returns get_user_config_dir + // is valid only on linux, otherwise returns get_user_config_dir fn get_legacy_user_config_dir(&self) -> Option<std::path::PathBuf>; fn spawn_java_process(&self, jre_dir: &std::path::PathBuf, args: &Vec<String>) -> std::process::Child; + // should probe HOME on linux and USERPROFILE on windows. + // it should have fallback in env::home_dir as it is doing a bit more + // see https://doc.rust-lang.org/std/env/fn.home_dir.html + fn get_home(&self) -> Option<std::path::PathBuf>; } pub struct Linux { @@ -48,7 +53,7 @@ } fn get_user_config_dir(&self) -> Option<std::path::PathBuf> { - match dirs_paths_helper::get_xdg_config_dir() { + match dirs_paths_helper::get_xdg_config_dir(self) { Some(mut p) => { p.push(dirs_paths_helper::ICEDTEA_WEB); Some(p) @@ -63,7 +68,7 @@ } fn get_legacy_user_config_dir(&self) -> Option<std::path::PathBuf> { - match dirs_paths_helper::get_home() { + match self.get_home() { Some(mut p) => { p.push(".icedtea"); Some(p) @@ -71,7 +76,7 @@ None => None } } - + fn spawn_java_process(&self, jre_dir: &std::path::PathBuf, args: &Vec<String>) -> std::process::Child { let mut bin_java = jre_dir.clone(); bin_java.push("bin"); @@ -90,4 +95,20 @@ java executable: [{}], arguments: [{:?}]", bin_java.into_os_string().to_str().expect("path should unwrap"), args) } } + + fn get_home(&self) -> Option<std::path::PathBuf> { + match env::var("HOME") { + Ok(war) => { + let home_var_path = std::path::PathBuf::from(war); + if dirs_paths_helper::is_dir(&home_var_path) { + return Some(home_var_path); + } + } + Err(_) => {} + } + // Not failing to env::get_home + // if this will ever be bugged, the fix should be to set HOME + // locally, or fix the distribution itslef + None + } }
--- a/rust-launcher/src/property_from_file.rs Fri Nov 30 19:12:09 2018 +0100 +++ b/rust-launcher/src/property_from_file.rs Mon Dec 10 14:44:28 2018 +0100 @@ -1,5 +1,6 @@ use property; use hardcoded_paths; +use dirs_paths_helper as dh; use std; use std::string::String; @@ -54,9 +55,6 @@ val.trim().to_lowercase() == "true" } -fn is_file(path: &std::path::PathBuf) -> bool { - path.metadata().map(|md| md.is_file()).unwrap_or(false) -} pub fn get_property_from_file(file: Option<std::path::PathBuf>, key: &str) -> Option<String> { @@ -71,7 +69,7 @@ fn get_property_from_file_direct(path: std::path::PathBuf, key: &str) -> Option<String> { if !path.exists() { None - } else if !is_file(&path) { + } else if !dh::is_file(&path) { return None; } else { let fileresult = File::open(path); @@ -102,7 +100,7 @@ file.push("java"); if !file.exists() { false - } else if !is_file(&file) { + } else if !dh::is_file(&file) { false } else { true @@ -120,21 +118,7 @@ super::get_property_from_file(file, super::JRE_PROPERTY_NAME) } - #[test] - fn is_not_file_() { - let r = super::is_file(&std::path::PathBuf::from("/definitely/not/existing/file")); - assert_eq!(false, r); - } - - #[test] - fn is_file_() { - let dir = tu::create_tmp_file(); - let r = super::is_file(&dir); - tu::debuggable_remove_file(&dir); - assert_eq!(true, r); - } - - #[test] + #[test] fn check_file_for_property_jredir_not_found() { let path = tu::create_tmp_file(); let f = File::open(&path);
--- a/rust-launcher/src/property_from_files_resolver.rs Fri Nov 30 19:12:09 2018 +0100 +++ b/rust-launcher/src/property_from_files_resolver.rs Mon Dec 10 14:44:28 2018 +0100 @@ -100,7 +100,7 @@ None } - fn spawn_java_process(&self, jre_dir: &std::path::PathBuf, args: &Vec<String>) -> std::process::Child { + fn spawn_java_process(&self, _jre_dir: &std::path::PathBuf, _args: &Vec<String>) -> std::process::Child { panic!("not implemented"); } @@ -119,6 +119,10 @@ fn get_legacy_user_config_dir(&self) -> Option<std::path::PathBuf> { panic!("not implemented"); } + + fn get_home(&self) -> Option<std::path::PathBuf> { + panic!("not implemented"); + } } fn try_jdk_from_properties_files(logger: &os_access::Os, array: &[Option<std::path::PathBuf>]) -> Option<String> {