chiark / gitweb /
progress: Actually send a progress report
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 12 May 2021 01:02:13 +0000 (02:02 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 12 May 2021 01:02:13 +0000 (02:02 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bundles.rs
src/prelude.rs
src/progress.rs

index 0ed5806999576072098fd93e8354df47a5a31489..82f75c5262044a8dba053fe74695c3317c97846d 100644 (file)
@@ -407,7 +407,7 @@ impl BundleParseErrorHandling for BundleParseUpload {
 
 #[throws(EH::Err)]
 fn parse_bundle<EH>(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<EH>(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)?
index 82db9dc793cc5463930042efefaa943ceb8a8cb9..e9c3462248660dd45e0e44d975a3f1df9b01b7f8 100644 (file)
@@ -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::*;
index 66c2005cc9aba3f39cde7f9e31fce6e93b6ca25f..a9692a51da695705bccb5528400e0a098df346ad 100644 (file)
@@ -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<W> 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<T> From<T> for Count<'static>
-where T: EnumCount + ToPrimitive + AsStaticRef<str>
+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<Count<'p>>,
-        E: Into<Count<'e>>,
+  fn phase_entry<P,E>(&mut self, phase: P, entry: E)
+  where for <'p> &'p P: Into<Count<'p>>,
+        for <'e> &'e E: Into<Count<'e>>,
   {
-    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 });
   }
 }