From: Ian Jackson Date: Wed, 12 May 2021 01:02:13 +0000 (+0100) Subject: progress: Actually send a progress report X-Git-Tag: otter-0.6.0~334 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1540ae251ed559ed411adb5c93c92ca4302ad274;p=otter.git progress: Actually send a progress report Signed-off-by: Ian Jackson --- diff --git a/src/bundles.rs b/src/bundles.rs index 0ed58069..82f75c52 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -407,7 +407,7 @@ impl BundleParseErrorHandling for BundleParseUpload { #[throws(EH::Err)] fn parse_bundle(id: Id, file: &mut dyn ReadSeek, eh: EH, - _for_progress: &mut dyn progress::Reporter) -> Parsed + mut for_progress: &mut dyn progress::Reporter) -> Parsed where EH: BundleParseErrorHandling, { match id.kind { Kind::Zip => () } @@ -415,6 +415,17 @@ fn parse_bundle(id: Id, file: &mut dyn ReadSeek, eh: EH, IndexedZip::new(file) })?; + #[derive(Copy,Clone,Debug,EnumCount,EnumMessage,ToPrimitive)] + enum Phase { + #[strum(message="scan")] Scan, + } + + #[derive(Copy,Clone,Debug,EnumCount,EnumMessage,ToPrimitive)] + enum ToScan { + #[strum(message="metadata")] Meta, + } + for_progress.phase_entry(Phase::Scan, ToScan::Meta); + let meta = eh.besteffort(||{ const META: &str = "otter.toml"; let mut mf = za.by_name_caseless(META)? diff --git a/src/prelude.rs b/src/prelude.rs index 82db9dc7..e9c34622 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -74,7 +74,7 @@ pub use log::{log, log_enabled}; pub use nix::unistd::{self, Uid}; pub use nix::sys::time::TimeSpec; pub use nix::time::clock_gettime; -pub use num_derive::FromPrimitive; +pub use num_derive::{ToPrimitive, FromPrimitive}; pub use num_traits::{Bounded, FromPrimitive, ToPrimitive}; pub use ordered_float::OrderedFloat; pub use parking_lot::{Condvar, Mutex, MutexGuard}; @@ -94,7 +94,8 @@ pub use serde_with::DeserializeFromStr; pub use serde_with::SerializeDisplay; pub use sha2::{Sha512, Sha512Trunc256}; pub use slotmap::{dense::DenseSlotMap, SparseSecondaryMap, Key as _}; -pub use strum::{AsStaticRef, EnumCount, EnumString, EnumIter, EnumProperty}; +pub use strum::{EnumCount}; +pub use strum::{EnumString, EnumIter, EnumMessage, EnumProperty}; pub use strum::{IntoEnumIterator, IntoStaticStr}; pub use subtle::ConstantTimeEq; pub use tempfile::NamedTempFile; @@ -150,7 +151,7 @@ pub use crate::packetframe::{ReadExt}; pub use crate::pcaliases::*; pub use crate::pcrender::*; pub use crate::pieces::*; -pub use crate::progress::{self, ProgressInfo}; +pub use crate::progress::{self, ProgressInfo, ReporterExt as _}; pub use crate::shapelib; pub use crate::shapelib::{CircleShape, RectShape}; pub use crate::slotmap_slot_idx::*; diff --git a/src/progress.rs b/src/progress.rs index 66c2005c..a9692a51 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -19,44 +19,39 @@ pub struct Count<'pi> { } pub trait Reporter { - fn report(&mut self, info: ProgressInfo<'_>) - -> Result<(), MgmtChannelWriteError>; + fn report(&mut self, info: ProgressInfo<'_>); } impl Reporter for ResponseWriter<'_, W> where W: Write { - #[throws(MgmtChannelWriteError)] fn report(&mut self, pi: ProgressInfo<'_>) { - self.progress(pi)? + self.progress(pi).unwrap_or(()); } } impl Reporter for () { - #[throws(MgmtChannelWriteError)] fn report(&mut self, _pi: ProgressInfo<'_>) { } } -impl From for Count<'static> -where T: EnumCount + ToPrimitive + AsStaticRef +impl<'t,T> From<&'t T> for Count<'t> +where T: EnumCount + ToPrimitive + EnumMessage { - fn from(t: T) -> Count<'static> { + fn from(t: &'t T) -> Count<'t> { Count { i: t.to_usize().unwrap(), n: T::COUNT, - desc: Cow::Borrowed(t.as_static()), + desc: Cow::Borrowed(t.get_message().unwrap_or("...")), } } } -#[ext(pub)] +#[ext(pub, name=ReporterExt)] impl &mut dyn Reporter { - #[throws(MgmtChannelWriteError)] - fn phase_entry<'p,'e,P,E>(&mut self, phase: P, entry: E) - where P: Into>, - E: Into>, + fn phase_entry(&mut self, phase: P, entry: E) + where for <'p> &'p P: Into>, + for <'e> &'e E: Into>, { - self.report(ProgressInfo { - phase: phase.into(), - entry: entry.into(), - })? + let phase = &phase; let phase = phase.into(); + let entry = &entry; let entry = entry.into(); + self.report(ProgressInfo { phase, entry }); } }