This allows progress reports to be disabled entirely.
But overall, no functional change.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
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(
};
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();
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)?;
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);
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 }
}
size: usize,
hash: bundles::Hash,
kind: bundles::Kind,
+ #[serde(default)] progress: ProgressUpdateMode,
},
ListBundles {
game: InstanceName,
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),
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::*;
// commands.rs
pub type ME = MgmtError;
+pub type PUM = ProgressUpdateMode;
// error.rs
pub type APOE = ApiPieceOpError;