summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinitard <solo@softwareag.com>2022-06-11 19:00:37 +0100
committerinitard <solo@softwareag.com>2022-06-16 15:18:10 +0100
commit39b4523cd3f795f45cfeb38d823f437432ee9d34 (patch)
treea566a9d04d2227e8e4158aa589dbfe8b6badda31
parentf9a0601a00c86a4383c8805e830960946a86219a (diff)
c8y_log_plugin fixing clippy warnings #825
Signed-off-by: initard <solo@softwareag.com>
-rw-r--r--plugins/c8y_log_plugin/src/config.rs3
-rw-r--r--plugins/c8y_log_plugin/src/logfile_request.rs8
-rw-r--r--plugins/c8y_log_plugin/src/main.rs24
3 files changed, 15 insertions, 20 deletions
diff --git a/plugins/c8y_log_plugin/src/config.rs b/plugins/c8y_log_plugin/src/config.rs
index 580fba95..8747bdf6 100644
--- a/plugins/c8y_log_plugin/src/config.rs
+++ b/plugins/c8y_log_plugin/src/config.rs
@@ -33,8 +33,7 @@ impl Borrow<String> for FileEntry {
impl LogPluginConfig {
pub fn new(config_file_path: &Path) -> Self {
- let config = Self::read_config(config_file_path);
- config
+ Self::read_config(config_file_path)
}
pub fn read_config(path: &Path) -> Self {
diff --git a/plugins/c8y_log_plugin/src/logfile_request.rs b/plugins/c8y_log_plugin/src/logfile_request.rs
index b538f714..f88afec5 100644
--- a/plugins/c8y_log_plugin/src/logfile_request.rs
+++ b/plugins/c8y_log_plugin/src/logfile_request.rs
@@ -115,8 +115,8 @@ pub fn new_read_logs(
) -> Result<String, anyhow::Error> {
let mut output = String::new();
// first filter logs on type
- let mut logfiles_to_read = filter_logs_on_type(&smartrest_obj, &plugin_config)?;
- logfiles_to_read = filter_logs_path_on_metadata(&smartrest_obj, logfiles_to_read)?;
+ let mut logfiles_to_read = filter_logs_on_type(smartrest_obj, plugin_config)?;
+ logfiles_to_read = filter_logs_path_on_metadata(smartrest_obj, logfiles_to_read)?;
let mut line_counter = 0usize;
for logfile in logfiles_to_read {
@@ -184,7 +184,7 @@ fn filter_logs_path_on_metadata(
};
// if the file metadata can not be read, we set the file's metadata
// to UNIX_EPOCH (Jan 1st 1970)
- return OffsetDateTime::UNIX_EPOCH;
+ OffsetDateTime::UNIX_EPOCH
});
logs_path_vec.reverse(); // to get most recent
@@ -219,7 +219,7 @@ async fn execute_logfile_request_operation(
let executing = LogfileRequest::executing()?;
let () = mqtt_client.published.send(executing).await?;
- let log_content = new_read_logs(&smartrest_request, &plugin_config)?;
+ let log_content = new_read_logs(smartrest_request, plugin_config)?;
let upload_event_url = http_client
.upload_log_binary(&smartrest_request.log_type, &log_content)
diff --git a/plugins/c8y_log_plugin/src/main.rs b/plugins/c8y_log_plugin/src/main.rs
index ce133bef..8a04589f 100644
--- a/plugins/c8y_log_plugin/src/main.rs
+++ b/plugins/c8y_log_plugin/src/main.rs
@@ -108,7 +108,7 @@ async fn run(
"522" => {
info!("Log request received: {payload}");
// retrieve smartrest object from payload
- let smartrest_obj = SmartRestLogRequest::from_smartrest(&payload)?;
+ let smartrest_obj = SmartRestLogRequest::from_smartrest(payload)?;
handle_logfile_request_operation(
&smartrest_obj,
&plugin_config,
@@ -134,16 +134,10 @@ async fn run(
return Ok(());
}
}
- Some(event_or_error) = inotify_stream.next() => {
- if let Ok(event) = event_or_error {
- match event.mask {
- EventMask::CLOSE_WRITE => {
- plugin_config = handle_dynamic_log_type_update(mqtt_client, config_file).await?;
- }
- _ => {}
- }
+ Some(Ok(event)) = inotify_stream.next() => {
+ if event.mask == EventMask::CLOSE_WRITE {
+ plugin_config = handle_dynamic_log_type_update(mqtt_client, config_file).await?;
}
-
}
}
}
@@ -184,10 +178,10 @@ async fn main() -> Result<(), anyhow::Error> {
Ok(())
}
-fn init(config_dir: &PathBuf, logs_dir: &PathBuf) -> Result<(), anyhow::Error> {
+fn init(config_dir: &Path, logs_dir: &Path) -> Result<(), anyhow::Error> {
info!("Creating supported operation files");
- let config_dir = config_dir.as_path().display().to_string();
- let logs_dir = logs_dir.as_path().display().to_string();
+ let config_dir = config_dir.display().to_string();
+ let logs_dir = logs_dir.display().to_string();
let () = create_init_logs_directories_and_files(config_dir.as_str(), logs_dir.as_str())?;
Ok(())
}
@@ -206,7 +200,9 @@ fn create_default_log_plugin_file(path_to_toml: &str, logs_dir: &str) -> Result<
.append(true)
.create(false)
.open(path_to_toml)
- .expect(&format!("Unable to open file: {}", path_to_toml));
+ .map_err(|error| {
+ anyhow::anyhow!("Unable to open file: {}. Error: {}", path_to_toml, error)
+ })?;
toml_file.write_all(data.to_string().as_bytes())?;
Ok(())
}