summaryrefslogtreecommitdiff
path: root/src/cmd/show_gen.rs
diff options
context:
space:
mode:
authorAlexander Batischev <eual.jp@gmail.com>2021-04-25 18:29:19 +0300
committerAlexander Batischev <eual.jp@gmail.com>2021-04-26 15:00:05 +0300
commit36c89315fad651b3b8ce1f8e25310db3ea668fae (patch)
tree64f15f87468b7eecf41b59b0fbf2f74369ce640b /src/cmd/show_gen.rs
parent80aaff3f70f790141fbc8caa8a2f4830cd5e3fee (diff)
downloadobnam2-36c89315fad651b3b8ce1f8e25310db3ea668fae.tar.gz
Expose fallibility of individual SQL results
`LocalGeneration::sql::files()` runs an SQL query, iterates over the results and collects the rows into a `Vec`. This can fail at any step: the query might fail to run, or one of the rows might fail to be fetched or processed. Right now, we lump all those failures into a `Result` that wraps the whole return value. This is only possible because we process each row before returning. Once `Vec` is replaced by an iterator, we won't have that luxury anymore, so we now wrap each individual element into its own `Result` (as well as wrapping the whole vector into a `Result` of its own).
Diffstat (limited to 'src/cmd/show_gen.rs')
-rw-r--r--src/cmd/show_gen.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/cmd/show_gen.rs b/src/cmd/show_gen.rs
index ba39809..7dc52cf 100644
--- a/src/cmd/show_gen.rs
+++ b/src/cmd/show_gen.rs
@@ -23,14 +23,17 @@ impl ShowGeneration {
let gen = client.fetch_generation(&gen_id, temp.path())?;
let files = gen.files()?;
- let total_bytes = files.iter().fold(0, |acc, file| {
- let e = file.entry();
- if e.kind() == FilesystemKind::Regular {
- acc + file.entry().len()
- } else {
- acc
- }
+ let total_bytes = files.into_iter().try_fold(0, |acc, file| {
+ file.map(|file| {
+ let e = file.entry();
+ if e.kind() == FilesystemKind::Regular {
+ acc + e.len()
+ } else {
+ acc
+ }
+ })
});
+ let total_bytes = total_bytes?;
println!("generation-id: {}", gen_id);
println!("file-count: {}", gen.file_count()?);