split up clean method
This commit is contained in:
@@ -256,17 +256,29 @@ fn fetch_sources(repo_path: &str, param: &OpenGitParam) -> Result<(), std::io::E
|
||||
}
|
||||
|
||||
fn clean_thread(thread_param: &ThreadRunningParam) {
|
||||
let mut eng = PodmanEngine::_new(thread_param.working_folder.clone());
|
||||
eng.list
|
||||
.container
|
||||
.iter()
|
||||
.position(|i| i.ide_id.eq(&thread_param.container.ide_id))
|
||||
.and_then(|ix| {
|
||||
eng.list.container.remove(ix);
|
||||
Some(0)
|
||||
})
|
||||
stop_container(thread_param);
|
||||
remove_container_and_sources(thread_param);
|
||||
}
|
||||
|
||||
fn remove_container_and_sources(thread_param: &ThreadRunningParam) {
|
||||
|
||||
upater_state(thread_param, &PodmanState::DeletingContainer, &IdeState::DELETING);
|
||||
|
||||
Command::new("podman")
|
||||
.arg("rm")
|
||||
.arg(&thread_param.container.ide_id)
|
||||
.status()
|
||||
.map(|_| ())
|
||||
.unwrap_or_default();
|
||||
eng.save().unwrap_or_default();
|
||||
|
||||
upater_state(thread_param, &PodmanState::DeletingSources, &IdeState::DELETING);
|
||||
fs::remove_dir_all(&thread_param.ide_folder).unwrap_or_default();
|
||||
upater_state(thread_param, &PodmanState::Unkown, &IdeState::DELETED);
|
||||
}
|
||||
|
||||
fn stop_container(thread_param: &ThreadRunningParam) {
|
||||
|
||||
upater_state(thread_param, &PodmanState::StoppingContainer, &IdeState::CLOSING);
|
||||
|
||||
Command::new("podman")
|
||||
.arg("stop")
|
||||
@@ -275,13 +287,19 @@ fn clean_thread(thread_param: &ThreadRunningParam) {
|
||||
.map(|_| ())
|
||||
.unwrap_or_default();
|
||||
|
||||
Command::new("podman")
|
||||
.arg("rm")
|
||||
.arg(&thread_param.container.ide_id)
|
||||
.status()
|
||||
.map(|_| ())
|
||||
.unwrap_or_default();
|
||||
fs::remove_dir_all(&thread_param.ide_folder).unwrap_or_default();
|
||||
upater_state(thread_param, &PodmanState::StoppedContainer, &IdeState::CLOSED);
|
||||
}
|
||||
|
||||
fn upater_state(thread_param: &ThreadRunningParam, podman_state : &PodmanState, ide_state : &IdeState) {
|
||||
let mut eng = PodmanEngine::_new(thread_param.working_folder.clone());
|
||||
match eng.find_mut_first_container(&thread_param.container.ide_id) {
|
||||
Some(i) => {
|
||||
i.state = podman_state.clone();
|
||||
i.ide_state = ide_state.clone();
|
||||
eng.save().map_err(|_| Error {}).unwrap_or_default();
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
fn working_thread(thread_param: &ThreadRunningParam) -> Result<(), Error> {
|
||||
|
||||
Reference in New Issue
Block a user