backup/datastore.rs: use DateTime<Utc> to store backup time

This commit is contained in:
Dietmar Maurer 2019-01-21 10:51:52 +01:00
parent be0084b001
commit 7ca80246ea
2 changed files with 7 additions and 6 deletions

View File

@ -8,6 +8,8 @@ use crate::backup::archive_index::*;
use crate::api::schema::*; use crate::api::schema::*;
use crate::api::router::*; use crate::api::router::*;
use chrono::{Utc, TimeZone};
use serde_json::Value; use serde_json::Value;
use std::io::Write; use std::io::Write;
use futures::*; use futures::*;
@ -115,6 +117,7 @@ fn download_catar(_parts: Parts, _req_body: Body, param: Value, _info: &ApiAsync
let backup_type = tools::required_string_param(&param, "type")?; let backup_type = tools::required_string_param(&param, "type")?;
let backup_id = tools::required_string_param(&param, "id")?; let backup_id = tools::required_string_param(&param, "id")?;
let backup_time = tools::required_integer_param(&param, "time")?; let backup_time = tools::required_integer_param(&param, "time")?;
let backup_time = Utc.timestamp(backup_time, 0);
println!("Download {}.catar from {} ({}/{}/{}/{}.aidx)", archive_name, store, println!("Download {}.catar from {} ({}/{}/{}/{}.aidx)", archive_name, store,
backup_type, backup_id, backup_time, archive_name); backup_type, backup_id, backup_time, archive_name);
@ -154,4 +157,3 @@ pub fn api_method_download_catar() -> ApiAsyncMethod {
) )
} }

View File

@ -26,7 +26,7 @@ pub struct DataStore {
pub struct BackupInfo { pub struct BackupInfo {
pub backup_type: String, pub backup_type: String,
pub backup_id: String, pub backup_id: String,
pub backup_time: i64, pub backup_time: DateTime<Utc>,
} }
lazy_static!{ lazy_static!{
@ -117,7 +117,7 @@ impl DataStore {
&self, &self,
backup_type: &str, backup_type: &str,
backup_id: &str, backup_id: &str,
backup_time: i64, backup_time: DateTime<Utc>,
) -> PathBuf { ) -> PathBuf {
let mut relative_path = PathBuf::new(); let mut relative_path = PathBuf::new();
@ -126,8 +126,7 @@ impl DataStore {
relative_path.push(backup_id); relative_path.push(backup_id);
let dt = Utc.timestamp(backup_time, 0); let date_str = backup_time.format("%Y-%m-%dT%H:%M:%S").to_string();
let date_str = dt.format("%Y-%m-%dT%H:%M:%S").to_string();
relative_path.push(&date_str); relative_path.push(&date_str);
@ -190,7 +189,7 @@ impl DataStore {
list.push(BackupInfo { list.push(BackupInfo {
backup_type: backup_type.to_owned(), backup_type: backup_type.to_owned(),
backup_id: backup_id.to_owned(), backup_id: backup_id.to_owned(),
backup_time: dt.timestamp(), backup_time: dt,
}); });
Ok(()) Ok(())