From 79c535955d2360cb8815c8d0caec153adce96bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Fri, 20 Nov 2020 17:38:41 +0100 Subject: [PATCH] refactor BackupInfo -> SnapshotListItem helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/api2/admin/datastore.rs | 50 +++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 48910b14..86d0847c 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -391,9 +391,11 @@ pub fn list_snapshots ( }; 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 (comment, verification, files, size) = match get_all_snapshot_files(&datastore, &info) { + match get_all_snapshot_files(&datastore, &info) { Ok((manifest, files)) => { // extract the first line from notes let comment: Option = manifest.unprotected["notes"] @@ -401,8 +403,8 @@ pub fn list_snapshots ( .and_then(|notes| notes.lines().next()) .map(String::from); - let verify = manifest.unprotected["verify_state"].clone(); - let verify: Option = match serde_json::from_value(verify) { + let verification = manifest.unprotected["verify_state"].clone(); + let verification: Option = match serde_json::from_value(verification) { Ok(verify) => verify, Err(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()); - (comment, verify, files, size) + SnapshotListItem { + backup_type, + backup_id, + backup_time, + comment, + verification, + files, + size, + owner, + } }, Err(err) => { eprintln!("error during snapshot file listing: '{}'", err); - ( - None, - None, - info + let files = info .files .into_iter() .map(|x| BackupContent { @@ -427,21 +435,19 @@ pub fn list_snapshots ( size: None, crypt_mode: None, }) - .collect(), - None, - ) - }, - }; + .collect(); - SnapshotListItem { - backup_type: group.backup_type().to_string(), - backup_id: group.backup_id().to_string(), - backup_time, - comment, - verification, - files, - size, - owner, + SnapshotListItem { + backup_type, + backup_id, + backup_time, + comment: None, + verification: None, + files, + size: None, + owner, + } + }, } };