-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ pub mod file_loop; | |
pub mod file_mmap; | ||
pub mod file_split; | ||
pub mod packer; | ||
|
||
pub mod rolling; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::plugin::file_split::Rolling; | ||
use fastdate::DateTime; | ||
use std::time::Duration; | ||
|
||
pub struct RollingAll {} | ||
impl Rolling for RollingAll { | ||
fn do_rolling(&self, dir: &str, temp_name: &str) -> i64 { | ||
0 | ||
} | ||
} | ||
|
||
pub struct RollingNum { | ||
pub num: i64, | ||
} | ||
|
||
impl Rolling for RollingNum { | ||
fn do_rolling(&self, dir: &str, temp_name: &str) -> i64 { | ||
let mut removed = 0; | ||
let paths_vec = self.read_paths(dir, temp_name); | ||
for index in 0..paths_vec.len() { | ||
if index >= (self.num) as usize { | ||
let item = &paths_vec[index]; | ||
std::fs::remove_file(item.path()); | ||
removed += 1; | ||
} | ||
} | ||
removed | ||
} | ||
} | ||
|
||
pub struct RollingTime { | ||
pub duration: Duration, | ||
} | ||
|
||
impl Rolling for RollingTime { | ||
fn do_rolling(&self, dir: &str, temp_name: &str) -> i64 { | ||
let mut removed = 0; | ||
let paths_vec = self.read_paths(dir, temp_name); | ||
let now = DateTime::now(); | ||
for index in 0..paths_vec.len() { | ||
let item = &paths_vec[index]; | ||
let file_name = item.file_name(); | ||
let name = file_name.to_str().unwrap_or("").to_string(); | ||
if let Some(time) = Self::file_name_parse_time(&name, temp_name) { | ||
if now.clone().sub(self.duration.clone()) > time { | ||
std::fs::remove_file(item.path()); | ||
removed += 1; | ||
} | ||
} | ||
} | ||
removed | ||
} | ||
} |