Skip to content

Commit

Permalink
refactor: remove useless async
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Mar 21, 2024
1 parent e012804 commit 9faf975
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/net/live_fluereflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub async fn online_packet_capture(arg: Args) {
.as_secs(),
));
let last_export = Arc::new(Mutex::new(Instant::now()));
let mut file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv").await;
let mut file = fs::File::create(file_path.clone()).unwrap();
let mut file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv");
let mut file = fs::File::create(file_path.as_ref()).unwrap();

//let mut wtr = csv::Writer::from_writer(file);

Expand Down Expand Up @@ -304,8 +304,8 @@ pub async fn online_packet_capture(arg: Args) {
/*if verbose >= 1 {
println!("Export {} result: {:?}", file_path, result);
}*/
file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv").await;
file = fs::File::create(file_path.clone()).unwrap();
file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv");
file = fs::File::create(file_path.as_ref()).unwrap();
*last_export_guard = Instant::now();
*last_export_unix_time_guard = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
Expand Down
4 changes: 2 additions & 2 deletions src/net/offline_fluereflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub async fn fluereflow_fileparse(arg: Args) -> Result<(), FluereError> {
};

let start = Instant::now();
let file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv").await;
let file = fs::File::create(file_path.clone()).unwrap();
let file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv");
let file = fs::File::create(file_path.as_ref()).unwrap();

//let mut wtr = csv::Writer::from_writer(file);

Expand Down
8 changes: 4 additions & 4 deletions src/net/online_fluereflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub async fn packet_capture(arg: Args) -> Result<(), FluereError> {

let start = Instant::now();
let mut last_export = Instant::now();
let mut file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv").await;
let mut file = fs::File::create(file_path.clone()).unwrap();
let mut file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv");
let mut file = fs::File::create(file_path.as_ref()).unwrap();

//let mut wtr = csv::Writer::from_writer(file);

Expand Down Expand Up @@ -217,8 +217,8 @@ pub async fn packet_capture(arg: Args) -> Result<(), FluereError> {

let result = tasks.await;
info!("Export {} result: {:?}", file_path, result);
file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv").await;
file = fs::File::create(file_path.clone()).unwrap();
file_path = cur_time_file(csv_file.as_str(), file_dir, ".csv");
file = fs::File::create(file_path.as_ref()).unwrap();
last_export = Instant::now();
}

Expand Down
4 changes: 2 additions & 2 deletions src/net/packet_pcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub async fn pcap_capture(args: Args) {
Err(error) => panic!("Problem creating directory: {:?}", error),
};

let file_path = cur_time_file(pcap_file.as_str(), file_dir, ".pcap").await;
let mut file: pcap::Savefile = match cap.savefile(file_path) {
let file_path = cur_time_file(pcap_file.as_str(), file_dir, ".pcap");
let mut file: pcap::Savefile = match cap.savefile(file_path.as_ref()) {
Ok(f) => f,
Err(_) => std::process::exit(1),
};
Expand Down
5 changes: 3 additions & 2 deletions src/utils/time_file_get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use chrono::Local;
use std::borrow::Cow;

pub async fn cur_time_file(name: &str, dir: &str, format: &str) -> String {
pub fn cur_time_file(name: &str, dir: &str, format: &str) -> Cow<'static, str> {
let date = Local::now();
let file_path = format!(
"{}/{}_{}{}",
Expand All @@ -10,5 +11,5 @@ pub async fn cur_time_file(name: &str, dir: &str, format: &str) -> String {
format
);

file_path
Cow::Owned(file_path)
}

0 comments on commit 9faf975

Please sign in to comment.