From 0c2c35ed22c00ae509d0c0a692e65e288ccf61fb Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 18 Apr 2024 14:33:00 +0100 Subject: [PATCH] Remove IoStreamSource We no longer use it with exec. --- src/docker/container.rs | 4 ++-- src/docker/iostream.rs | 44 ++++++++--------------------------------- src/docker/mod.rs | 2 -- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/src/docker/container.rs b/src/docker/container.rs index 2380f90..5d1463e 100644 --- a/src/docker/container.rs +++ b/src/docker/container.rs @@ -14,7 +14,7 @@ use tokio::signal::unix::{signal, SignalKind}; use tokio::task::{spawn, JoinHandle}; use tokio_stream::StreamExt; -use super::{IoStream, IoStreamSource}; +use super::IoStream; use crate::cgroup::{ Access, DeviceAccessController, DeviceAccessControllerDummy, DeviceAccessControllerV1, DeviceAccessControllerV2, DeviceType, @@ -202,7 +202,7 @@ impl Container { Ok(IoStream { output: response.output, input: response.input, - source: IoStreamSource::Container(self.id.clone()), + id: self.id.clone(), docker: self.docker.clone(), }) } diff --git a/src/docker/iostream.rs b/src/docker/iostream.rs index 063bfa4..d07e220 100644 --- a/src/docker/iostream.rs +++ b/src/docker/iostream.rs @@ -10,15 +10,10 @@ use tokio::task::JoinHandle; use tokio_stream::{Stream, StreamExt}; use tokio_util::io::ReaderStream; -pub(super) enum IoStreamSource { - Container(String), - Exec(String), -} - pub struct IoStream { pub output: std::pin::Pin> + Send>>, pub input: Pin>, - pub(super) source: IoStreamSource, + pub(super) id: String, pub(super) docker: bollard::Docker, } @@ -30,14 +25,6 @@ enum StreamData { } impl IoStream { - pub async fn collect(mut self) -> Result { - let mut result = String::default(); - while let Some(output) = self.output.next().await { - result.push_str(&output?.to_string()); - } - Ok(result) - } - pub fn pipe_std(self) -> JoinHandle> { let stdin = crate::util::tty_mode_guard::TtyModeGuard::new(tokio::io::stdin(), |mode| { // Switch input to raw mode, but don't touch output modes (as it can also be connected @@ -72,7 +59,7 @@ impl IoStream { ) -> JoinHandle> { let mut input = self.input; let docker = self.docker; - let source = self.source; + let id = self.id; let resize_stream = resize_stream.map(|data| { let (rows, cols) = data.context("Listening for tty resize")?; @@ -101,7 +88,7 @@ impl IoStream { while let Some(data) = streams.next().await { match data? { StreamData::Resize(rows, cols) => { - resize_tty(&docker, &source, (rows, cols)).await?; + resize_tty(&docker, &id, (rows, cols)).await?; } StreamData::StdIn(mut buf) => { input.write_all_buf(&mut buf).await?; @@ -123,26 +110,11 @@ impl IoStream { } } -async fn resize_tty( - docker: &bollard::Docker, - source: &IoStreamSource, - (rows, cols): (u16, u16), -) -> Result<()> { - match source { - IoStreamSource::Container(id) => { - let options = bollard::container::ResizeContainerTtyOptions { - height: rows, - width: cols, - }; - docker.resize_container_tty(id, options).await?; - } - IoStreamSource::Exec(id) => { - let options = bollard::exec::ResizeExecOptions { - height: rows, - width: cols, - }; - docker.resize_exec(id, options).await?; - } +async fn resize_tty(docker: &bollard::Docker, id: &str, (rows, cols): (u16, u16)) -> Result<()> { + let options = bollard::container::ResizeContainerTtyOptions { + height: rows, + width: cols, }; + docker.resize_container_tty(id, options).await?; Ok(()) } diff --git a/src/docker/mod.rs b/src/docker/mod.rs index 4025f5d..32c48f5 100644 --- a/src/docker/mod.rs +++ b/src/docker/mod.rs @@ -5,5 +5,3 @@ mod iostream; pub use container::Container; pub use docker::Docker; pub use iostream::IoStream; - -use iostream::IoStreamSource;