Skip to content

Commit

Permalink
fix(Clippy): Fixes a set of new clippy warning and allows one rule
Browse files Browse the repository at this point in the history
The allowed one is related to rust-lang/rust-clippy#13458 as we start as tokio::main and never return.
  • Loading branch information
avrabe committed Oct 5, 2024
1 parent 0feb479 commit 8972c52
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 73 deletions.
21 changes: 5 additions & 16 deletions src/container_ostree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -107,23 +107,12 @@ fn _read_revision_from_file<P: AsRef<Path>>(path: P) -> Result<RevisionData, Box
#[derive(Debug)]
pub struct ChunkMetaData {
pub rev: Option<String>,
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);
Expand Down
63 changes: 23 additions & 40 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -163,18 +161,10 @@ async fn main() {
for chunk in update.chunks() {
info!("Retrieving {}\n", chunk.name());
let mut rev: Option<String> = 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),
}
}
Expand All @@ -192,13 +182,7 @@ async fn main() {
warn!("For application {}, an't find a commit in version {} even though the option is set. Expect <version>:<commit> 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);
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -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");
}
}
4 changes: 0 additions & 4 deletions src/ostree.rs
Original file line number Diff line number Diff line change
@@ -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,
}
25 changes: 12 additions & 13 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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]
Expand All @@ -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()
}

0 comments on commit 8972c52

Please sign in to comment.