refactor BackupInfo -> SnapshotListItem helper
before adding more fields to the tuple, let's just create the struct inside the match arms to improve readability. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
8b7f8d3f3d
commit
79c535955d
|
@ -391,9 +391,11 @@ pub fn list_snapshots (
|
||||||
};
|
};
|
||||||
|
|
||||||
let info_to_snapshot_list_item = |group: &BackupGroup, owner, info: BackupInfo| {
|
let info_to_snapshot_list_item = |group: &BackupGroup, owner, info: BackupInfo| {
|
||||||
|
let backup_type = group.backup_type().to_string();
|
||||||
|
let backup_id = group.backup_id().to_string();
|
||||||
let backup_time = info.backup_dir.backup_time();
|
let backup_time = info.backup_dir.backup_time();
|
||||||
|
|
||||||
let (comment, verification, files, size) = match get_all_snapshot_files(&datastore, &info) {
|
match get_all_snapshot_files(&datastore, &info) {
|
||||||
Ok((manifest, files)) => {
|
Ok((manifest, files)) => {
|
||||||
// extract the first line from notes
|
// extract the first line from notes
|
||||||
let comment: Option<String> = manifest.unprotected["notes"]
|
let comment: Option<String> = manifest.unprotected["notes"]
|
||||||
|
@ -401,8 +403,8 @@ pub fn list_snapshots (
|
||||||
.and_then(|notes| notes.lines().next())
|
.and_then(|notes| notes.lines().next())
|
||||||
.map(String::from);
|
.map(String::from);
|
||||||
|
|
||||||
let verify = manifest.unprotected["verify_state"].clone();
|
let verification = manifest.unprotected["verify_state"].clone();
|
||||||
let verify: Option<SnapshotVerifyState> = match serde_json::from_value(verify) {
|
let verification: Option<SnapshotVerifyState> = match serde_json::from_value(verification) {
|
||||||
Ok(verify) => verify,
|
Ok(verify) => verify,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("error parsing verification state : '{}'", err);
|
eprintln!("error parsing verification state : '{}'", err);
|
||||||
|
@ -412,14 +414,20 @@ pub fn list_snapshots (
|
||||||
|
|
||||||
let size = Some(files.iter().map(|x| x.size.unwrap_or(0)).sum());
|
let size = Some(files.iter().map(|x| x.size.unwrap_or(0)).sum());
|
||||||
|
|
||||||
(comment, verify, files, size)
|
SnapshotListItem {
|
||||||
|
backup_type,
|
||||||
|
backup_id,
|
||||||
|
backup_time,
|
||||||
|
comment,
|
||||||
|
verification,
|
||||||
|
files,
|
||||||
|
size,
|
||||||
|
owner,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("error during snapshot file listing: '{}'", err);
|
eprintln!("error during snapshot file listing: '{}'", err);
|
||||||
(
|
let files = info
|
||||||
None,
|
|
||||||
None,
|
|
||||||
info
|
|
||||||
.files
|
.files
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| BackupContent {
|
.map(|x| BackupContent {
|
||||||
|
@ -427,21 +435,19 @@ pub fn list_snapshots (
|
||||||
size: None,
|
size: None,
|
||||||
crypt_mode: None,
|
crypt_mode: None,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect();
|
||||||
None,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
SnapshotListItem {
|
SnapshotListItem {
|
||||||
backup_type: group.backup_type().to_string(),
|
backup_type,
|
||||||
backup_id: group.backup_id().to_string(),
|
backup_id,
|
||||||
backup_time,
|
backup_time,
|
||||||
comment,
|
comment: None,
|
||||||
verification,
|
verification: None,
|
||||||
files,
|
files,
|
||||||
size,
|
size: None,
|
||||||
owner,
|
owner,
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue