Skip to content

Commit

Permalink
Remove IoStreamSource
Browse files Browse the repository at this point in the history
We no longer use it with exec.
  • Loading branch information
nbdd0121 committed Apr 20, 2024
1 parent ec3ac8d commit 0c2c35e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/docker/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
})
}
Expand Down
44 changes: 8 additions & 36 deletions src/docker/iostream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Stream<Item = Result<LogOutput, Error>> + Send>>,
pub input: Pin<Box<dyn AsyncWrite + Send>>,
pub(super) source: IoStreamSource,
pub(super) id: String,
pub(super) docker: bollard::Docker,
}

Expand All @@ -30,14 +25,6 @@ enum StreamData {
}

impl IoStream {
pub async fn collect(mut self) -> Result<String> {
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<Result<()>> {
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
Expand Down Expand Up @@ -72,7 +59,7 @@ impl IoStream {
) -> JoinHandle<Result<()>> {
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")?;
Expand Down Expand Up @@ -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?;
Expand All @@ -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(())
}
2 changes: 0 additions & 2 deletions src/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ mod iostream;
pub use container::Container;
pub use docker::Docker;
pub use iostream::IoStream;

use iostream::IoStreamSource;

0 comments on commit 0c2c35e

Please sign in to comment.