chiark / gitweb /
progress: Introduce ProgressMode
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 10:36:37 +0000 (11:36 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 14:00:29 +0000 (15:00 +0100)
This allows progress reports to be disabled entirely.

But overall, no functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/bin/otter.rs
src/bundles.rs
src/commands.rs
src/prelude.rs

index 34bc09ccabafc6b01d7ef48995e72075e599d1b2..2e7498f327cab96d9be926496e6684e5af08e8a0 100644 (file)
@@ -255,7 +255,7 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
       resp
     }
 
-    MC::UploadBundle { game, size, hash, kind } => {
+    MC::UploadBundle { game, size, hash, kind, progress } => {
       let (upload, auth) = {
         let (ag, gref) = start_access_game(&game)?;
         access_bundles(
@@ -267,7 +267,7 @@ fn execute_and_respond<W>(cs: &mut CommandStreamData, cmd: MgmtCommand,
       };
       bulk_upload.inner_mut().set_timeout(Some(UPLOAD_TIMEOUT));
       let uploaded = upload.bulk(bulk_upload, size,
-                                 &hash, &mut for_response)?;
+                                 &hash, progress, &mut for_response)?;
       {
         let gref = Instance::lookup_by_name(&game, auth)?;
         let mut bundles = gref.lock_bundles();
index 1b23b86aefb37fa22950d068029f2c83dbde12b1..66be469a3857647fb44839720fd77a335b42410e 100644 (file)
@@ -1398,6 +1398,7 @@ mod upload_bundle {
       size,
       game: instance_name.clone(),
       hash: bundles::Hash(hash.into()), kind,
+      progress: PUM::Simplex,
     };
     let mut progress = termprogress::new();
     chan.cmd_withbulk(&cmd, &mut f, &mut io::sink(), &mut *progress)?;
index 58b466c6ea4a0af13460736caceffe402450f389..b695c4fa0e623aedfb4be1894e9e917c55d8e76f 100644 (file)
@@ -871,17 +871,27 @@ impl InstanceBundles {
 impl Uploading {
   #[throws(MgmtError)]
   pub fn bulk<R,PW>(self, data: R, size: usize, expected: &Hash,
-                    for_progress: &mut ResponseWriter<PW>) -> Uploaded
+                    progress_mode: ProgressUpdateMode,
+                    progress_stream: &mut ResponseWriter<PW>) -> Uploaded
   where R: Read, PW: Write
   {
-    let mut for_progress = progress::ResponseOriginator::new(for_progress);
+    let mut for_progress_buf;
+    let mut null_progress = ();
+    let for_progress: &mut dyn progress::Originator =
+      if progress_mode >= PUM::Simplex {
+        for_progress_buf = progress::ResponseOriginator::new(progress_stream);
+        &mut for_progress_buf
+      } else {
+        &mut null_progress
+      };
 
     let Uploading { id, mut file, instance } = self;
     let tmp = id.path_tmp(&instance);
 
     let mut null_progress = ();
     let for_progress_upload: &mut dyn progress::Originator =
-      if false { &mut for_progress } else { &mut null_progress };
+      if progress_mode >= PUM::Duplex
+      { for_progress } else { &mut null_progress };
     
     let mut data_reporter = progress::ReadOriginator::new(
       for_progress_upload, Phase::Upload, size, data);
@@ -904,9 +914,9 @@ impl Uploading {
     file.rewind().context("rewind"). map_err(IE::from)?;
 
     let (za, parsed) = parse_bundle(id, &instance, file, BundleParseUpload,
-                                    &mut for_progress)?;
+                                    for_progress)?;
 
-    process_bundle(za, id, &*instance, &mut for_progress)?;
+    process_bundle(za, id, &*instance, for_progress)?;
 
     Uploaded { id, parsed }
   }
index ceec49be55484cb7e9db01129b75ac9239d11c99..0c3f0645ca8b98c54dc5640e79a82e3c474224ef 100644 (file)
@@ -44,6 +44,7 @@ pub enum MgmtCommand {
     size: usize,
     hash: bundles::Hash,
     kind: bundles::Kind,
+    #[serde(default)] progress: ProgressUpdateMode,
   },
   ListBundles {
     game: InstanceName,
@@ -210,6 +211,16 @@ pub enum MgmtGameUpdateMode {
   Bulk,
 }
 
+#[derive(Debug,Copy,Clone,Eq,PartialEq,Ord,PartialOrd,Serialize,Deserialize)]
+pub enum ProgressUpdateMode {
+  None,
+  Simplex,
+  Duplex,
+}
+impl Default for ProgressUpdateMode {
+  fn default() -> Self { PUM::None }
+}
+
 #[derive(Debug,Clone,Error,Serialize,Deserialize)]
 pub enum MgmtError {
   #[error("failed to parse protocol command: {0}")] CommandParseFailed(String),
index 24dc31004c7116d62f61741344a2365daa665c97..8b8f9b3e33e1e13a57166c3d9c550601f7fe3bfc 100644 (file)
@@ -133,6 +133,7 @@ pub use crate::commands::{AccessTokenInfo, AccessTokenReport, MgmtError};
 pub use crate::commands::{MgmtCommand, MgmtResponse};
 pub use crate::commands::{MgmtGameInstruction, MgmtGameResponse};
 pub use crate::commands::{MgmtBundleList, MgmtGameUpdateMode};
+pub use crate::commands::{ProgressUpdateMode};
 pub use crate::config::*;
 pub use crate::debugreader::DebugReader;
 pub use crate::error::*;
@@ -182,6 +183,7 @@ pub type AS = AccountScope;
 
 // commands.rs
 pub type ME = MgmtError;
+pub type PUM = ProgressUpdateMode;
 
 // error.rs
 pub type APOE = ApiPieceOpError;