Cleanup and modernize
+ Bump to rust 2024 + Cleaned up old code + Added more fail safes in case certain files are missing
This commit is contained in:
+10
-13
@@ -8,6 +8,7 @@ pub mod file;
|
||||
pub mod ftp;
|
||||
pub mod sftp;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait RemoteBackupFile {
|
||||
/// Type containing the location of the remote_backup backup
|
||||
type LocationType;
|
||||
@@ -16,14 +17,14 @@ pub trait RemoteBackupFile {
|
||||
fn location(&self) -> Self::LocationType;
|
||||
|
||||
/// Get the time the remote_backup file was created
|
||||
fn time_created(&self) -> chrono::NaiveDateTime;
|
||||
fn time_created(&self) -> NaiveDateTime;
|
||||
|
||||
/// Parse the time created from the file name
|
||||
fn parse_file_name(file_name: &str) -> Option<chrono::NaiveDateTime> {
|
||||
fn parse_file_name(file_name: &str) -> Option<NaiveDateTime> {
|
||||
let time: Vec<&str> = file_name.split("_backup.tar.gz").collect();
|
||||
|
||||
if let Some(time_str) = time.get(0) {
|
||||
chrono::NaiveDateTime::parse_from_str(time_str, "%d-%m-%y_%H.%M.%S").ok()
|
||||
if let Some(time_str) = time.first() {
|
||||
NaiveDateTime::parse_from_str(time_str, "%d-%m-%y_%H.%M.%S").ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -34,7 +35,7 @@ pub trait RemoteBackupSite {
|
||||
/// Struct representing the location of a backup on the site
|
||||
type FileType: RemoteBackupFile;
|
||||
|
||||
/// Backup a file to the the remote_backup site
|
||||
/// Backup a file to the remote_backup site
|
||||
fn backup_to_remote(&mut self, file: PathBuf) -> Result<()>;
|
||||
|
||||
/// Get the locations backups contained on the remote_backup site
|
||||
@@ -80,14 +81,10 @@ impl PathLocation {
|
||||
if let Some(file_name) = path.file_name() {
|
||||
let file_name = file_name.to_str().unwrap();
|
||||
|
||||
if let Some(time) = Self::parse_file_name(file_name) {
|
||||
Some(Self {
|
||||
location: path,
|
||||
time_created: time,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
Self::parse_file_name(file_name).map(|time| Self {
|
||||
location: path,
|
||||
time_created: time,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user