refactor: Remove numerous clones()

get_container_name_by_id clone, init_all_log refactor to remove clones,
remove id.clone() by using SpawnId.get_id()
This commit is contained in:
Jack Wills
2024-12-03 16:37:38 +00:00
parent de72ab47cd
commit e5927f781a
6 changed files with 93 additions and 92 deletions
+10 -7
View File
@@ -144,9 +144,9 @@ impl TerminalSize {
#[derive(Debug, Clone)]
pub enum ExecMode {
// use Bollard Rust library
Internal((ContainerId, Arc<Docker>)),
Internal((Arc<ContainerId>, Arc<Docker>)),
// use the external `docker-cli`
External(ContainerId),
External(Arc<ContainerId>),
}
impl ExecMode {
@@ -186,7 +186,10 @@ impl ExecMode {
{
if let Some(Ok(msg)) = output.next().await {
if !msg.to_string().starts_with(OCI_ERROR) {
return Some(Self::Internal((id.clone(), Arc::clone(docker))));
return Some(Self::Internal((
Arc::new(id),
Arc::clone(docker),
)));
}
}
}
@@ -199,7 +202,7 @@ impl ExecMode {
{
if let Ok(output) = String::from_utf8(output.stdout) {
if !output.starts_with(OCI_ERROR) {
return Some(Self::External(id.clone()));
return Some(Self::External(Arc::new(id)));
}
}
}
@@ -302,9 +305,9 @@ impl ExecMode {
Ok(())
}
// This is the fix for key pressed not being handled correctly on quit
// It writes a special message to the stdout, and then listens out for a valid response
// afterwhich it's assumes that we're completely done with TTY
/// This is the fix for key pressed not being handled correctly on quit
/// It writes a special message to the stdout, and then listens out for a valid response
/// afterwhich it's assumes that we're completely done with TTY
fn internal_cleanup(&self) -> Result<(), AppError> {
match self {
Self::External(_) => Ok(()),