diff --git a/src/container_ostree.rs b/src/container_ostree.rs index 4ff4528..238f38f 100644 --- a/src/container_ostree.rs +++ b/src/container_ostree.rs @@ -63,7 +63,7 @@ mod tests { let tmp_dir = TempDir::new("example").unwrap(); create_repo(tmp_dir.path().to_str().unwrap()); // For now check if there are files inside. - assert_eq!(path_is_empty(tmp_dir.path().to_str().unwrap()), false); + assert!(!path_is_empty(tmp_dir.path().to_str().unwrap())); tmp_dir.close().unwrap(); } } @@ -107,23 +107,12 @@ fn _read_revision_from_file>(path: P) -> Result, - pub autostart: bool, - pub autoremove: bool, - pub notify: bool, - pub timeout: u32, + //pub autostart: bool, + //pub autoremove: bool, + //pub notify: bool, + //pub timeout: u32, } -impl Default for ChunkMetaData { - fn default() -> Self { - ChunkMetaData { - rev: None, - autostart: false, - autoremove: false, - notify: false, - timeout: 30, - } - } -} // Returns a ostree user repo from a given directory- pub fn get_repo(path: &str) -> ostree::Repo { create_repo(path); diff --git a/src/main.rs b/src/main.rs index 49d20c7..c31d4a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,6 +70,7 @@ pub fn get_log_level(level: &str) -> Level { } #[tokio::main] +#[allow(clippy::needless_return)] async fn main() { // Get the command line arguments let opts: Opts = Opts::parse(); @@ -109,7 +110,6 @@ async fn main() { if !application_exists(application.to_string()) { let chunk_meta_data: ChunkMetaData = ChunkMetaData { rev: Some(format!("{application}:{application}")), - ..Default::default() }; checkout_container(&chunk_meta_data, &application); } @@ -153,8 +153,6 @@ async fn main() { Err(error) => panic!("Problem opening the file: {error:?}"), }; - //dbg!(&update); - update .send_feedback(Execution::Proceeding, Finished::None, vec!["Downloading"]) .await @@ -163,18 +161,10 @@ async fn main() { for chunk in update.chunks() { info!("Retrieving {}\n", chunk.name()); let mut rev: Option = None; - let mut autostart: bool = false; - let mut autoremove: bool = false; - let mut notify: bool = false; - let mut timeout: u32 = 0; for metadata in chunk.metadata() { match metadata { ("rev", _) => rev = Some(metadata.1.to_string()), - ("autostart", _) => autostart = metadata.1 == "1", - ("autoremove", _) => autoremove = metadata.1 == "1", - ("notify", _) => notify = metadata.1 == "1", - ("timeout", _) => timeout = metadata.1.parse().unwrap(), (_, _) => info!("unknown metadata {:#?}", metadata), } } @@ -192,13 +182,7 @@ async fn main() { warn!("For application {}, an't find a commit in version {} even though the option is set. Expect : as version.", chunk.name(), chunk.version()); } } - let chunk_meta_data: ChunkMetaData = ChunkMetaData { - rev, - autostart, - autoremove, - notify, - timeout, - }; + let chunk_meta_data: ChunkMetaData = ChunkMetaData { rev }; info!("metadata: {:#?}", chunk_meta_data); let unit = chunk.name(); stop_unit(unit); @@ -225,24 +209,6 @@ async fn main() { info!("sleep for {:?}", t); sleep(t).await; } - //dbg!(&reply); - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn no_loglevel_in_ini() { - let ini = Ini::new(); - assert_eq!(read_loglevel_configuration(&ini), "DEBUG"); - } - - #[test] - fn no_servername_in_ini() { - let ini = Ini::new(); - assert_eq!(read_server_configuration(&ini), "localhost"); } } @@ -308,12 +274,29 @@ fn read_ostree_configuration(conf: Ini, server_host_name: String) -> OstreeOpts hostname: format!( "{ostree_url_type}{server_host_name}:{ostree_url_port}/{ostree_url_prefix}" ), - ostree_name_remote: get_ini_string(section, "ostree_name_remote"), + //ostree_name_remote: get_ini_string(section, "ostree_name_remote"), ostree_gpg_verify: get_ini_bool(section, "ostree_gpg-verify"), - ostreepush_ssh_user: get_ini_string(section, "ostreepush_ssh_user"), - ostreepush_ssh_pwd: get_ini_string(section, "ostreepush_ssh_pwd"), - ostreepush_ssh_port: get_ini_string(section, "ostreepush_ssh_port"), + //ostreepush_ssh_user: get_ini_string(section, "ostreepush_ssh_user"), + //ostreepush_ssh_pwd: get_ini_string(section, "ostreepush_ssh_pwd"), + //ostreepush_ssh_port: get_ini_string(section, "ostreepush_ssh_port"), }; info!("{:?}", ostree_opts); ostree_opts } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn no_loglevel_in_ini() { + let ini = Ini::new(); + assert_eq!(read_loglevel_configuration(&ini), "DEBUG"); + } + + #[test] + fn no_servername_in_ini() { + let ini = Ini::new(); + assert_eq!(read_server_configuration(&ini), "localhost"); + } +} diff --git a/src/ostree.rs b/src/ostree.rs index 91c1c70..f6b4295 100644 --- a/src/ostree.rs +++ b/src/ostree.rs @@ -1,9 +1,5 @@ #[derive(Debug)] pub struct OstreeOpts { pub hostname: String, - pub ostree_name_remote: String, pub ostree_gpg_verify: bool, - pub ostreepush_ssh_port: String, - pub ostreepush_ssh_user: String, - pub ostreepush_ssh_pwd: String, } diff --git a/src/utils.rs b/src/utils.rs index 1f5e356..5fa1436 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,10 +1,18 @@ use std::{fs::metadata, path::PathBuf}; +pub fn path_exists(path: &str) -> bool { + metadata(path).is_ok() +} + +pub fn path_is_empty(path: &str) -> bool { + let dir_path_buf = PathBuf::from(path); + dir_path_buf.read_dir().unwrap().next().is_none() +} + #[cfg(test)] mod tests { - use tempdir::TempDir; - use super::*; + use tempdir::TempDir; #[test] fn current_path() { @@ -13,12 +21,12 @@ mod tests { #[test] fn bad_path() { - assert_eq!(path_exists("./sadsad/"), false); + assert!(!path_exists("./sadsad/")); } #[test] fn path_is_not_empty() { - assert_eq!(path_is_empty("./"), false); + assert!(!path_is_empty("./")); } #[test] @@ -28,12 +36,3 @@ mod tests { tmp_dir.close().unwrap(); } } - -pub fn path_exists(path: &str) -> bool { - metadata(path).is_ok() -} - -pub fn path_is_empty(path: &str) -> bool { - let dir_path_buf = PathBuf::from(path); - dir_path_buf.read_dir().unwrap().next().is_none() -}