From 90d098ff74856bf5845de825cb85af3cff7ca6a1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 17 May 2021 11:36:37 +0100 Subject: [PATCH] progress: Introduce ProgressMode This allows progress reports to be disabled entirely. But overall, no functional change. Signed-off-by: Ian Jackson --- daemon/cmdlistener.rs | 4 ++-- src/bin/otter.rs | 1 + src/bundles.rs | 20 +++++++++++++++----- src/commands.rs | 11 +++++++++++ src/prelude.rs | 2 ++ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 34bc09cc..2e7498f3 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -255,7 +255,7 @@ fn execute_and_respond(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(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(); diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 1b23b86a..66be469a 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -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)?; diff --git a/src/bundles.rs b/src/bundles.rs index 58b466c6..b695c4fa 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -871,17 +871,27 @@ impl InstanceBundles { impl Uploading { #[throws(MgmtError)] pub fn bulk(self, data: R, size: usize, expected: &Hash, - for_progress: &mut ResponseWriter) -> Uploaded + progress_mode: ProgressUpdateMode, + progress_stream: &mut ResponseWriter) -> 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 } } diff --git a/src/commands.rs b/src/commands.rs index ceec49be..0c3f0645 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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), diff --git a/src/prelude.rs b/src/prelude.rs index 24dc3100..8b8f9b3e 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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; -- 2.30.2