-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: finalize basic Windows build #139
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #139 +/- ##
==========================================
- Coverage 37.93% 37.91% -0.02%
==========================================
Files 18 23 +5
Lines 493 720 +227
Branches 2 2
==========================================
+ Hits 187 273 +86
- Misses 306 447 +141
☔ View full report in Codecov by Sentry. |
ed54eda
to
b24b676
Compare
b24b676
to
f1c5cbb
Compare
WalkthroughThe changes encompass enhancements to configuration files, workflow automation, and the introduction of new functionalities within the project. Key modifications include updates to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant ClamAV
participant ConfigManager
User->>App: Initiates ClamAV command
App->>ConfigManager: Fetches configuration
ConfigManager-->>App: Returns configuration
App->>ClamAV: Executes command with config
ClamAV-->>App: Returns command result
App-->>User: Displays result
Recent review detailsConfiguration used: CodeRabbit UI Files ignored due to path filters (13)
Files selected for processing (73)
Additional context usedLearnings (1)
LanguageTool
Additional comments not posted (207)
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 15
mod common; | ||
|
||
use std::env; | ||
use common::execute_clamav_command; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().skip(1).collect(); | ||
execute_clamav_command("clamd", args); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling and logging.
The code correctly collects command-line arguments and executes a ClamAV command, but it lacks error handling and logging for better traceability.
Apply this diff to add error handling and logging:
+use std::process::exit;
+use log::{info, error};
fn main() {
+ env_logger::init();
let args: Vec<String> = env::args().skip(1).collect();
+ info!("Executing clamd with arguments: {:?}", args);
if let Err(e) = execute_clamav_command("clamd", args) {
+ error!("Failed to execute clamd: {}", e);
+ exit(1);
+ }
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
mod common; | |
use std::env; | |
use common::execute_clamav_command; | |
fn main() { | |
let args: Vec<String> = env::args().skip(1).collect(); | |
execute_clamav_command("clamd", args); | |
} | |
mod common; | |
use std::env; | |
use std::process::exit; | |
use log::{info, error}; | |
use common::execute_clamav_command; | |
fn main() { | |
env_logger::init(); | |
let args: Vec<String> = env::args().skip(1).collect(); | |
info!("Executing clamd with arguments: {:?}", args); | |
if let Err(e) = execute_clamav_command("clamd", args) { | |
error!("Failed to execute clamd: {}", e); | |
exit(1); | |
} | |
} |
mod common; | ||
|
||
use std::env; | ||
use common::execute_clamav_command; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().skip(1).collect(); | ||
execute_clamav_command("clamscan", args); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling and logging.
The code correctly collects command-line arguments and executes a ClamAV command, but it lacks error handling and logging for better traceability.
Apply this diff to add error handling and logging:
+use std::process::exit;
+use log::{info, error};
fn main() {
+ env_logger::init();
let args: Vec<String> = env::args().skip(1).collect();
+ info!("Executing clamscan with arguments: {:?}", args);
if let Err(e) = execute_clamav_command("clamscan", args) {
+ error!("Failed to execute clamscan: {}", e);
+ exit(1);
+ }
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
mod common; | |
use std::env; | |
use common::execute_clamav_command; | |
fn main() { | |
let args: Vec<String> = env::args().skip(1).collect(); | |
execute_clamav_command("clamscan", args); | |
} | |
mod common; | |
use std::env; | |
use std::process::exit; | |
use log::{info, error}; | |
use common::execute_clamav_command; | |
fn main() { | |
env_logger::init(); | |
let args: Vec<String> = env::args().skip(1).collect(); | |
info!("Executing clamscan with arguments: {:?}", args); | |
if let Err(e) = execute_clamav_command("clamscan", args) { | |
error!("Failed to execute clamscan: {}", e); | |
exit(1); | |
} | |
} |
@@ -7,7 +7,7 @@ pub struct CloudSharedState(pub CloudState); | |||
|
|||
#[derive(Default)] | |||
pub struct CloudState { | |||
pub private: CloudPrivateState, | |||
// pub private: CloudPrivateState, | |||
pub public: Arc<Mutex<CloudPublicState>>, | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unused CloudPrivateState
struct.
The CloudPrivateState
struct is defined but not used, indicating it might be redundant. Consider removing it to clean up the code.
Apply this diff to remove the unused CloudPrivateState
struct:
-#[derive(Default)]
-pub struct CloudPrivateState {}
Committable suggestion was skipped due to low confidence.
@@ -7,7 +7,7 @@ pub struct DashboardSharedState(pub DashboardState); | |||
|
|||
#[derive(Default)] | |||
pub struct DashboardState { | |||
pub private: DashboardPrivateState, | |||
// pub private: DashboardPrivateState, | |||
pub public: Arc<Mutex<DashboardPublicState>>, | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unused DashboardPrivateState
struct.
The DashboardPrivateState
struct is defined but not used, indicating it might be redundant. Consider removing it to clean up the code.
Apply this diff to remove the unused DashboardPrivateState
struct:
-#[derive(Default)]
-pub struct DashboardPrivateState {}
Committable suggestion was skipped due to low confidence.
pub fn execute_clamav_command(binary_name: &str, args: Vec<String>) { | ||
let resource_path = resolve_binary_path(binary_name); | ||
|
||
let status = Command::new(resource_path) | ||
.args(&args) | ||
.status() | ||
.expect(&format!("Failed to execute {}", binary_name)); | ||
|
||
exit(status.code().unwrap_or(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for the status code.
The function correctly executes the command and exits with the status code, but it does not handle potential errors when the status code is not available. Consider adding error handling for this case.
Apply this diff to add error handling:
- exit(status.code().unwrap_or(1));
+ exit(status.code().expect("Failed to get status code"));
Committable suggestion was skipped due to low confidence.
tokio::spawn(async move { | ||
crate::libs::logger::write_log_message("debug.csv", &scope, &message).await; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling within the spawned task.
The spawned task should handle errors returned by the write_log_message
function to ensure that any issues are logged or managed appropriately.
Apply this diff to add error handling within the spawned task:
tokio::spawn(async move {
- crate::libs::logger::write_log_message("debug.csv", &scope, &message).await;
+ if let Err(e) = crate::libs::logger::write_log_message("debug.csv", &scope, &message).await {
+ eprintln!("Failed to write debug log: {}", e);
+ }
});
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
tokio::spawn(async move { | |
crate::libs::logger::write_log_message("debug.csv", &scope, &message).await; | |
}); | |
tokio::spawn(async move { | |
if let Err(e) = crate::libs::logger::write_log_message("debug.csv", &scope, &message).await { | |
eprintln!("Failed to write debug log: {}", e); | |
} | |
}); |
let log_directory_path = LOG_DIRECTORY_PATH | ||
.lock() | ||
.expect("Failed to lock log directory path."); | ||
pub async fn write_log_message(log_file_name: &str, scope: &str, message: &str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling by using Result
.
The function should return a Result
instead of using expect
for error handling. This will make the function more robust and allow the caller to handle errors appropriately.
Apply this diff to improve error handling:
-pub async fn write_log_message(log_file_name: &str, scope: &str, message: &str) {
+pub async fn write_log_message(log_file_name: &str, scope: &str, message: &str) -> Result<(), Box<dyn std::error::Error>> {
let log_directory_path = LOG_DIRECTORY_PATH.lock().await;
let log_directory_path_clone = log_directory_path.clone();
if !log_directory_path_clone.exists() {
- fs::create_dir_all(&log_directory_path_clone).expect("Failed to create log directory.");
+ fs::create_dir_all(&log_directory_path_clone)?;
}
let log_file_path_as_path_buf = log_directory_path.join(log_file_name);
let log_file_path_as_str = log_file_path_as_path_buf
- .to_str()
- .expect("Failed to convert log file path to string.");
+ .to_str().ok_or("Failed to convert log file path to string.")?;
let mut log_file = OpenOptions::new()
.create(true)
.append(true)
- .open(log_file_path_as_str)
- .expect(format!("Failed to open `{}` file.", log_file_path_as_str).as_str());
+ .open(log_file_path_as_str)?;
writeln!(
log_file,
"{},{},{}",
Utc::now().to_rfc3339(),
scope,
message
- )
- .expect("Failed to write to log file.");
+ )?;
+ Ok(())
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
pub async fn write_log_message(log_file_name: &str, scope: &str, message: &str) { | |
pub async fn write_log_message(log_file_name: &str, scope: &str, message: &str) -> Result<(), Box<dyn std::error::Error>> { | |
let log_directory_path = LOG_DIRECTORY_PATH.lock().await; | |
let log_directory_path_clone = log_directory_path.clone(); | |
if !log_directory_path_clone.exists() { | |
fs::create_dir_all(&log_directory_path_clone)?; | |
} | |
let log_file_path_as_path_buf = log_directory_path.join(log_file_name); | |
let log_file_path_as_str = log_file_path_as_path_buf | |
.to_str().ok_or("Failed to convert log file path to string.")?; | |
let mut log_file = OpenOptions::new() | |
.create(true) | |
.append(true) | |
.open(log_file_path_as_str)?; | |
writeln!( | |
log_file, | |
"{},{},{}", | |
Utc::now().to_rfc3339(), | |
scope, | |
message | |
)?; | |
Ok(()) | |
} |
#[test] | ||
fn test_clamscan_write() { | ||
let test_config_path = Path::new("test_config_write.conf"); | ||
|
||
let mut file = File::create(&test_config_path).expect("Failed to create test config file"); | ||
writeln!( | ||
file, | ||
"DatabaseMirror \"test.database.clamav.net\"\nMaxAttempts 3\nScriptedUpdates yes\nLogVerbose no\nExtraDatabase \"extra.db1\"\nExtraDatabase \"extra.db2\"\nLogFileMaxSize 5M" | ||
) | ||
.expect("Failed to write to test config file"); | ||
|
||
let config = Config::from_file(&test_config_path).expect("Failed to read test config file"); | ||
|
||
let mut modified_config = config; | ||
modified_config.set_value( | ||
"DatabaseMirror", | ||
ConfigValue::StringVal("modified.database.clamav.net".to_string()), | ||
); | ||
modified_config.set_value("MaxAttempts", ConfigValue::U32Val(5)); | ||
modified_config.set_value("ScriptedUpdates", ConfigValue::YesNoVal(YesNo::No)); | ||
modified_config.set_value("LogVerbose", ConfigValue::YesNoVal(YesNo::Yes)); | ||
modified_config.set_value( | ||
"ExtraDatabase", | ||
ConfigValue::StringListVal(vec!["modified.db1".to_string(), "modified.db2".to_string()]), | ||
); | ||
modified_config.set_value("LogFileMaxSize", ConfigValue::SizedStringVal("10M".to_string())); | ||
modified_config | ||
.to_file(&test_config_path) | ||
.expect("Failed to write modified config file"); | ||
|
||
let modified_config = Config::from_file(&test_config_path).expect("Failed to read modified config file"); | ||
|
||
assert!(matches!( | ||
modified_config.get_value("DatabaseMirror"), | ||
Some(ConfigValue::StringVal(val)) if val == "modified.database.clamav.net" | ||
)); | ||
assert!(matches!( | ||
modified_config.get_value("MaxAttempts"), | ||
Some(ConfigValue::U32Val(5)) | ||
)); | ||
assert!(matches!( | ||
modified_config.get_value("ScriptedUpdates"), | ||
Some(ConfigValue::YesNoVal(YesNo::No)) | ||
)); | ||
assert!(matches!( | ||
modified_config.get_value("LogVerbose"), | ||
Some(ConfigValue::YesNoVal(YesNo::Yes)) | ||
)); | ||
assert!(matches!( | ||
modified_config.get_value("ExtraDatabase"), | ||
Some(ConfigValue::StringListVal(vals)) if *vals == vec!["modified.db1".to_string(), "modified.db2".to_string()] | ||
)); | ||
assert!(matches!( | ||
modified_config.get_value("LogFileMaxSize"), | ||
Some(ConfigValue::SizedStringVal(val)) if val == "10M" | ||
)); | ||
|
||
std::fs::remove_file(test_config_path).expect("Failed to remove test config file"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a temporary directory for the test file.
To avoid any potential conflicts with existing files, use a temporary directory for the test file.
Apply this diff to use a temporary directory for the test file:
use std::fs::File;
use std::io::Write;
use std::path::Path;
+use tempfile::tempdir;
use config::freshclam::Config;
use config::{ConfigValue, YesNo};
#[test]
fn test_clamscan_write() {
- let test_config_path = Path::new("test_config_write.conf");
+ let dir = tempdir().expect("Failed to create temp dir");
+ let test_config_path = dir.path().join("test_config_write.conf");
let mut file = File::create(&test_config_path).expect("Failed to create test config file");
writeln!(
file,
"DatabaseMirror \"test.database.clamav.net\"\nMaxAttempts 3\nScriptedUpdates yes\nLogVerbose no\nExtraDatabase \"extra.db1\"\nExtraDatabase \"extra.db2\"\nLogFileMaxSize 5M"
)
.expect("Failed to write to test config file");
let config = Config::from_file(&test_config_path).expect("Failed to read test config file");
let mut modified_config = config;
modified_config.set_value(
"DatabaseMirror",
ConfigValue::StringVal("modified.database.clamav.net".to_string()),
);
modified_config.set_value("MaxAttempts", ConfigValue::U32Val(5));
modified_config.set_value("ScriptedUpdates", ConfigValue::YesNoVal(YesNo::No));
modified_config.set_value("LogVerbose", ConfigValue::YesNoVal(YesNo::Yes));
modified_config.set_value(
"ExtraDatabase",
ConfigValue::StringListVal(vec!["modified.db1".to_string(), "modified.db2".to_string()]),
);
modified_config.set_value("LogFileMaxSize", ConfigValue::SizedStringVal("10M".to_string()));
modified_config
.to_file(&test_config_path)
.expect("Failed to write modified config file");
let modified_config = Config::from_file(&test_config_path).expect("Failed to read modified config file");
assert!(matches!(
modified_config.get_value("DatabaseMirror"),
Some(ConfigValue::StringVal(val)) if val == "modified.database.clamav.net"
));
assert!(matches!(
modified_config.get_value("MaxAttempts"),
Some(ConfigValue::U32Val(5))
));
assert!(matches!(
modified_config.get_value("ScriptedUpdates"),
Some(ConfigValue::YesNoVal(YesNo::No))
));
assert!(matches!(
modified_config.get_value("LogVerbose"),
Some(ConfigValue::YesNoVal(YesNo::Yes))
));
assert!(matches!(
modified_config.get_value("ExtraDatabase"),
Some(ConfigValue::StringListVal(vals)) if *vals == vec!["modified.db1".to_string(), "modified.db2".to_string()]
));
assert!(matches!(
modified_config.get_value("LogFileMaxSize"),
Some(ConfigValue::SizedStringVal(val)) if val == "10M"
));
- std::fs::remove_file(test_config_path).expect("Failed to remove test config file");
+ dir.close().expect("Failed to remove temp dir");
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
#[test] | |
fn test_clamscan_write() { | |
let test_config_path = Path::new("test_config_write.conf"); | |
let mut file = File::create(&test_config_path).expect("Failed to create test config file"); | |
writeln!( | |
file, | |
"DatabaseMirror \"test.database.clamav.net\"\nMaxAttempts 3\nScriptedUpdates yes\nLogVerbose no\nExtraDatabase \"extra.db1\"\nExtraDatabase \"extra.db2\"\nLogFileMaxSize 5M" | |
) | |
.expect("Failed to write to test config file"); | |
let config = Config::from_file(&test_config_path).expect("Failed to read test config file"); | |
let mut modified_config = config; | |
modified_config.set_value( | |
"DatabaseMirror", | |
ConfigValue::StringVal("modified.database.clamav.net".to_string()), | |
); | |
modified_config.set_value("MaxAttempts", ConfigValue::U32Val(5)); | |
modified_config.set_value("ScriptedUpdates", ConfigValue::YesNoVal(YesNo::No)); | |
modified_config.set_value("LogVerbose", ConfigValue::YesNoVal(YesNo::Yes)); | |
modified_config.set_value( | |
"ExtraDatabase", | |
ConfigValue::StringListVal(vec!["modified.db1".to_string(), "modified.db2".to_string()]), | |
); | |
modified_config.set_value("LogFileMaxSize", ConfigValue::SizedStringVal("10M".to_string())); | |
modified_config | |
.to_file(&test_config_path) | |
.expect("Failed to write modified config file"); | |
let modified_config = Config::from_file(&test_config_path).expect("Failed to read modified config file"); | |
assert!(matches!( | |
modified_config.get_value("DatabaseMirror"), | |
Some(ConfigValue::StringVal(val)) if val == "modified.database.clamav.net" | |
)); | |
assert!(matches!( | |
modified_config.get_value("MaxAttempts"), | |
Some(ConfigValue::U32Val(5)) | |
)); | |
assert!(matches!( | |
modified_config.get_value("ScriptedUpdates"), | |
Some(ConfigValue::YesNoVal(YesNo::No)) | |
)); | |
assert!(matches!( | |
modified_config.get_value("LogVerbose"), | |
Some(ConfigValue::YesNoVal(YesNo::Yes)) | |
)); | |
assert!(matches!( | |
modified_config.get_value("ExtraDatabase"), | |
Some(ConfigValue::StringListVal(vals)) if *vals == vec!["modified.db1".to_string(), "modified.db2".to_string()] | |
)); | |
assert!(matches!( | |
modified_config.get_value("LogFileMaxSize"), | |
Some(ConfigValue::SizedStringVal(val)) if val == "10M" | |
)); | |
std::fs::remove_file(test_config_path).expect("Failed to remove test config file"); | |
} | |
use std::fs::File; | |
use std::io::Write; | |
use std::path::Path; | |
use tempfile::tempdir; | |
use config::freshclam::Config; | |
use config::{ConfigValue, YesNo}; | |
#[test] | |
fn test_clamscan_write() { | |
let dir = tempdir().expect("Failed to create temp dir"); | |
let test_config_path = dir.path().join("test_config_write.conf"); | |
let mut file = File::create(&test_config_path).expect("Failed to create test config file"); | |
writeln!( | |
file, | |
"DatabaseMirror \"test.database.clamav.net\"\nMaxAttempts 3\nScriptedUpdates yes\nLogVerbose no\nExtraDatabase \"extra.db1\"\nExtraDatabase \"extra.db2\"\nLogFileMaxSize 5M" | |
) | |
.expect("Failed to write to test config file"); | |
let config = Config::from_file(&test_config_path).expect("Failed to read test config file"); | |
let mut modified_config = config; | |
modified_config.set_value( | |
"DatabaseMirror", | |
ConfigValue::StringVal("modified.database.clamav.net".to_string()), | |
); | |
modified_config.set_value("MaxAttempts", ConfigValue::U32Val(5)); | |
modified_config.set_value("ScriptedUpdates", ConfigValue::YesNoVal(YesNo::No)); | |
modified_config.set_value("LogVerbose", ConfigValue::YesNoVal(YesNo::Yes)); | |
modified_config.set_value( | |
"ExtraDatabase", | |
ConfigValue::StringListVal(vec!["modified.db1".to_string(), "modified.db2".to_string()]), | |
); | |
modified_config.set_value("LogFileMaxSize", ConfigValue::SizedStringVal("10M".to_string())); | |
modified_config | |
.to_file(&test_config_path) | |
.expect("Failed to write modified config file"); | |
let modified_config = Config::from_file(&test_config_path).expect("Failed to read modified config file"); | |
assert!(matches!( | |
modified_config.get_value("DatabaseMirror"), | |
Some(ConfigValue::StringVal(val)) if val == "modified.database.clamav.net" | |
)); | |
assert!(matches!( | |
modified_config.get_value("MaxAttempts"), | |
Some(ConfigValue::U32Val(5)) | |
)); | |
assert!(matches!( | |
modified_config.get_value("ScriptedUpdates"), | |
Some(ConfigValue::YesNoVal(YesNo::No)) | |
)); | |
assert!(matches!( | |
modified_config.get_value("LogVerbose"), | |
Some(ConfigValue::YesNoVal(YesNo::Yes)) | |
)); | |
assert!(matches!( | |
modified_config.get_value("ExtraDatabase"), | |
Some(ConfigValue::StringListVal(vals)) if *vals == vec!["modified.db1".to_string(), "modified.db2".to_string()] | |
)); | |
assert!(matches!( | |
modified_config.get_value("LogFileMaxSize"), | |
Some(ConfigValue::SizedStringVal(val)) if val == "10M" | |
)); | |
dir.close().expect("Failed to remove temp dir"); | |
} |
#[tauri::command] | ||
pub async fn start_copilot_checklist(app_handle: AppHandle) -> Result<(), ()> { | ||
debug!("start_checklist()", "Command call."); | ||
|
||
let mut current_checklist_step = 0.0; | ||
let checklist_length = constants::CHECKLIST.len() as f32; | ||
|
||
state::set_public_state_module_status(&app_handle, globals::ModuleStatus::Running, true).await; | ||
|
||
for checklist_item in constants::CHECKLIST.iter() { | ||
match checklist_item { | ||
constants::ChecklistItem::CheckClamscanSidecar => { | ||
current_checklist_step += 1.0; | ||
let next_checklist_progress = current_checklist_step / checklist_length; | ||
|
||
state::set_public_state_current_checklist_progress(&app_handle, next_checklist_progress, false).await; | ||
state::set_public_state_current_checklist_item(&app_handle, Some(checklist_item), true).await; | ||
|
||
let result = check_sidecar("clamscan").await; | ||
match result { | ||
Ok(_) => (), | ||
Err(error_message) => { | ||
error!("start_checklist()", "{}", error_message.as_str()); | ||
|
||
state::set_public_state_current_checklist_error(&app_handle, Some(error_message), false).await; | ||
state::set_public_state_module_status(&app_handle, globals::ModuleStatus::Failed, true).await; | ||
|
||
return Err(()); | ||
} | ||
} | ||
} | ||
|
||
constants::ChecklistItem::CheckFreshclamSidecar => { | ||
current_checklist_step += 1.0; | ||
let next_checklist_progress = current_checklist_step / checklist_length; | ||
|
||
state::set_public_state_current_checklist_progress(&app_handle, next_checklist_progress, false).await; | ||
state::set_public_state_current_checklist_item(&app_handle, Some(checklist_item), true).await; | ||
|
||
let result = check_sidecar("freshclam").await; | ||
match result { | ||
Ok(_) => (), | ||
Err(error_message) => { | ||
error!("start_checklist()", "{}", error_message.as_str()); | ||
|
||
state::set_public_state_current_checklist_error(&app_handle, Some(error_message), false).await; | ||
state::set_public_state_module_status(&app_handle, globals::ModuleStatus::Failed, true).await; | ||
|
||
return Err(()); | ||
} | ||
} | ||
} | ||
|
||
constants::ChecklistItem::CheckFreshclamConfig => { | ||
current_checklist_step += 1.0; | ||
let next_checklist_progress = current_checklist_step / checklist_length; | ||
|
||
state::set_public_state_current_checklist_progress(&app_handle, next_checklist_progress, false).await; | ||
state::set_public_state_current_checklist_item(&app_handle, Some(checklist_item), true).await; | ||
|
||
let result = check_freshclam_config(&app_handle).await; | ||
match result { | ||
Ok(_) => (), | ||
Err(error_message) => { | ||
error!("start_checklist()", "{}", error_message.as_str()); | ||
|
||
state::set_public_state_current_checklist_error(&app_handle, Some(error_message), false).await; | ||
state::set_public_state_module_status(&app_handle, globals::ModuleStatus::Failed, true).await; | ||
|
||
return Err(()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
state::set_public_state(&app_handle, state::CopilotPublicState::default(), false).await; | ||
|
||
Ok(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding additional error handling.
The start_copilot_checklist
function is correctly implemented but could benefit from additional error handling to ensure robustness.
Consider adding error handling for potential issues that may arise during the checklist iteration.
async fn check_freshclam_config(app_handle: &AppHandle) -> Result<(), String> { | ||
debug!("check_freshclam_config()", "Function call."); | ||
|
||
let config_directory_path_mutex_guard = globals::CONFIG_DIRECTORY_PATH.lock().await; | ||
let local_data_directory_path_mutex_guard = globals::LOCAL_DATA_DIRECTORY_PATH.lock().await; | ||
|
||
let config_directory_path = config_directory_path_mutex_guard.clone(); | ||
let local_data_directory_path = local_data_directory_path_mutex_guard.clone(); | ||
let local_data_directory_path_as_string = local_data_directory_path.as_path().to_str().unwrap().to_string(); | ||
let freshclam_config_file_path = config_directory_path.join("freshclam.conf"); | ||
if freshclam_config_file_path.exists() { | ||
let mut freshclam_config = config::freshclam::Config::from_file(freshclam_config_file_path.as_path()) | ||
.expect("Failed to parse freshclam config file."); | ||
if freshclam_config.get_value("DatabaseDirectory") | ||
!= Some(&config::ConfigValue::StringVal( | ||
local_data_directory_path_as_string.clone(), | ||
)) | ||
{ | ||
freshclam_config.set_value( | ||
"DatabaseDirectory", | ||
config::ConfigValue::StringVal(local_data_directory_path_as_string.clone()), | ||
); | ||
} | ||
if freshclam_config.get_value("DatabaseMirror") | ||
!= Some(&config::ConfigValue::StringVal("database.clamav.net".to_string())) | ||
{ | ||
freshclam_config.set_value( | ||
"DatabaseMirror", | ||
config::ConfigValue::StringVal("database.clamav.net".to_string()), | ||
); | ||
} | ||
|
||
let result = freshclam_config.to_file(freshclam_config_file_path.as_path()); | ||
|
||
if result.is_err() { | ||
return Err(format!( | ||
"Failed to update `{}`.", | ||
freshclam_config_file_path.to_str().unwrap() | ||
)); | ||
} | ||
|
||
return Ok(()); | ||
} | ||
|
||
state::set_public_state_is_fixing_current_checklist_item(app_handle, true, true).await; | ||
|
||
let mut freshclam_config = config::freshclam::Config::new(); | ||
|
||
freshclam_config.set_value( | ||
"DatabaseDirectory", | ||
config::ConfigValue::StringVal(local_data_directory_path_as_string.clone()), | ||
); | ||
freshclam_config.set_value( | ||
"DatabaseMirror", | ||
config::ConfigValue::StringVal("database.clamav.net".to_string()), | ||
); | ||
|
||
let result = freshclam_config.to_file(freshclam_config_file_path.as_path()); | ||
|
||
state::set_public_state_is_fixing_current_checklist_item(app_handle, false, true).await; | ||
|
||
if result.is_err() { | ||
return Err(format!( | ||
"Failed to update `{}`.", | ||
freshclam_config_file_path.to_str().unwrap() | ||
)); | ||
} | ||
|
||
return Ok(()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding additional error handling.
The check_freshclam_config
function is correctly implemented but could benefit from additional error handling to ensure robustness.
Consider adding error handling for potential issues that may arise during the configuration check and update.
Description
A clear and concise description of what your pull request is about.
Checklist