src/backup/datastore.rs: protect BackupGroup fields, impl new()
This commit is contained in:
parent
cdebd467e6
commit
1e9a94e579
|
@ -76,8 +76,8 @@ fn list_groups(
|
||||||
let group = &info.backup_dir.group;
|
let group = &info.backup_dir.group;
|
||||||
|
|
||||||
groups.push(json!({
|
groups.push(json!({
|
||||||
"backup-type": group.backup_type,
|
"backup-type": group.backup_type(),
|
||||||
"backup-id": group.backup_id,
|
"backup-id": group.backup_id(),
|
||||||
"last-backup": info.backup_dir.backup_time.timestamp(),
|
"last-backup": info.backup_dir.backup_time.timestamp(),
|
||||||
"backup-count": list.len() as u64,
|
"backup-count": list.len() as u64,
|
||||||
"files": info.files,
|
"files": info.files,
|
||||||
|
@ -100,10 +100,7 @@ fn delete_snapshots (
|
||||||
let backup_time = Local.timestamp(backup_time, 0);
|
let backup_time = Local.timestamp(backup_time, 0);
|
||||||
|
|
||||||
let snapshot = BackupDir {
|
let snapshot = BackupDir {
|
||||||
group: BackupGroup {
|
group: BackupGroup::new(backup_type, backup_id),
|
||||||
backup_type: backup_type.to_owned(),
|
|
||||||
backup_id: backup_id.to_owned(),
|
|
||||||
},
|
|
||||||
backup_time,
|
backup_time,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -124,10 +121,7 @@ fn list_snapshots (
|
||||||
let backup_type = tools::required_string_param(¶m, "backup-type")?;
|
let backup_type = tools::required_string_param(¶m, "backup-type")?;
|
||||||
let backup_id = tools::required_string_param(¶m, "backup-id")?;
|
let backup_id = tools::required_string_param(¶m, "backup-id")?;
|
||||||
|
|
||||||
let group = BackupGroup {
|
let group = BackupGroup::new(backup_type, backup_id);
|
||||||
backup_type: backup_type.to_owned(),
|
|
||||||
backup_id: backup_id.to_owned(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let datastore = DataStore::lookup_datastore(store)?;
|
let datastore = DataStore::lookup_datastore(store)?;
|
||||||
|
|
||||||
|
@ -153,8 +147,8 @@ fn list_snapshots (
|
||||||
let group = &info.backup_dir.group;
|
let group = &info.backup_dir.group;
|
||||||
|
|
||||||
snapshots.push(json!({
|
snapshots.push(json!({
|
||||||
"backup-type": group.backup_type,
|
"backup-type": group.backup_type(),
|
||||||
"backup-id": group.backup_id,
|
"backup-id": group.backup_id(),
|
||||||
"backup-time": info.backup_dir.backup_time.timestamp(),
|
"backup-time": info.backup_dir.backup_time.timestamp(),
|
||||||
"files": info.files,
|
"files": info.files,
|
||||||
}));
|
}));
|
||||||
|
@ -335,8 +329,8 @@ fn get_backup_list(
|
||||||
|
|
||||||
for info in datastore.list_backups()? {
|
for info in datastore.list_backups()? {
|
||||||
list.push(json!({
|
list.push(json!({
|
||||||
"backup-type": info.backup_dir.group.backup_type,
|
"backup-type": info.backup_dir.group.backup_type(),
|
||||||
"backup-id": info.backup_dir.group.backup_id,
|
"backup-id": info.backup_dir.group.backup_id(),
|
||||||
"backup-time": info.backup_dir.backup_time.timestamp(),
|
"backup-time": info.backup_dir.backup_time.timestamp(),
|
||||||
"files": info.files,
|
"files": info.files,
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -146,10 +146,7 @@ fn download_catar(
|
||||||
let datastore = DataStore::lookup_datastore(store)?;
|
let datastore = DataStore::lookup_datastore(store)?;
|
||||||
|
|
||||||
let backup_dir = BackupDir {
|
let backup_dir = BackupDir {
|
||||||
group: BackupGroup {
|
group: BackupGroup::new(backup_type, backup_id),
|
||||||
backup_type: backup_type.to_string(),
|
|
||||||
backup_id: backup_id.to_string(),
|
|
||||||
},
|
|
||||||
backup_time,
|
backup_time,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,25 @@ pub struct DataStore {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BackupGroup {
|
pub struct BackupGroup {
|
||||||
/// Type of backup
|
/// Type of backup
|
||||||
pub backup_type: String,
|
backup_type: String,
|
||||||
/// Unique (for this type) ID
|
/// Unique (for this type) ID
|
||||||
pub backup_id: String,
|
backup_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BackupGroup {
|
impl BackupGroup {
|
||||||
|
|
||||||
|
pub fn new<T: Into<String>>(backup_type: T, backup_id: T) -> Self {
|
||||||
|
Self { backup_type: backup_type.into(), backup_id: backup_id.into() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn backup_type(&self) -> &str {
|
||||||
|
&self.backup_type
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn backup_id(&self) -> &str {
|
||||||
|
&self.backup_id
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(path: &str) -> Result<Self, Error> {
|
pub fn parse(path: &str) -> Result<Self, Error> {
|
||||||
|
|
||||||
let cap = GROUP_PATH_REGEX.captures(path)
|
let cap = GROUP_PATH_REGEX.captures(path)
|
||||||
|
|
|
@ -113,10 +113,7 @@ fn list_backups(
|
||||||
let backup_time = Local.timestamp(epoch, 0);
|
let backup_time = Local.timestamp(epoch, 0);
|
||||||
|
|
||||||
let backup_dir = BackupDir {
|
let backup_dir = BackupDir {
|
||||||
group: BackupGroup {
|
group: BackupGroup::new(btype, id),
|
||||||
backup_type: btype.to_string(),
|
|
||||||
backup_id: id.to_string(),
|
|
||||||
},
|
|
||||||
backup_time
|
backup_time
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,10 +157,7 @@ fn list_backup_groups(
|
||||||
let last_backup = Local.timestamp(epoch, 0);
|
let last_backup = Local.timestamp(epoch, 0);
|
||||||
let backup_count = item["backup-count"].as_u64().unwrap();
|
let backup_count = item["backup-count"].as_u64().unwrap();
|
||||||
|
|
||||||
let group = BackupGroup {
|
let group = BackupGroup::new(btype, id);
|
||||||
backup_type: btype.to_string(),
|
|
||||||
backup_id: id.to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let path = group.group_path().to_str().unwrap().to_owned();
|
let path = group.group_path().to_str().unwrap().to_owned();
|
||||||
|
|
||||||
|
@ -193,8 +187,8 @@ fn list_snapshots(
|
||||||
let group = BackupGroup::parse(path)?;
|
let group = BackupGroup::parse(path)?;
|
||||||
|
|
||||||
let query = tools::json_object_to_query(json!({
|
let query = tools::json_object_to_query(json!({
|
||||||
"backup-type": &group.backup_type,
|
"backup-type": group.backup_type(),
|
||||||
"backup-id": &group.backup_id,
|
"backup-id": group.backup_id(),
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
let mut client = HttpClient::new(&repo.host, &repo.user);
|
let mut client = HttpClient::new(&repo.host, &repo.user);
|
||||||
|
@ -215,10 +209,7 @@ fn list_snapshots(
|
||||||
let backup_time = Local.timestamp(epoch, 0);
|
let backup_time = Local.timestamp(epoch, 0);
|
||||||
|
|
||||||
let snapshot = BackupDir {
|
let snapshot = BackupDir {
|
||||||
group: BackupGroup {
|
group: BackupGroup::new(btype, id),
|
||||||
backup_type: btype.to_string(),
|
|
||||||
backup_id: id.to_string(),
|
|
||||||
},
|
|
||||||
backup_time,
|
backup_time,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -248,8 +239,8 @@ fn forget_snapshots(
|
||||||
let snapshot = BackupDir::parse(path)?;
|
let snapshot = BackupDir::parse(path)?;
|
||||||
|
|
||||||
let query = tools::json_object_to_query(json!({
|
let query = tools::json_object_to_query(json!({
|
||||||
"backup-type": &snapshot.group.backup_type,
|
"backup-type": snapshot.group.backup_type(),
|
||||||
"backup-id": &snapshot.group.backup_id,
|
"backup-id": snapshot.group.backup_id(),
|
||||||
"backup-time": snapshot.backup_time.timestamp(),
|
"backup-time": snapshot.backup_time.timestamp(),
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue