add clean thread
This commit is contained in:
@@ -150,9 +150,12 @@ impl NixIdeManageServiceEngine for PodmanEngineTraitImpl {
|
||||
param: param.clone(),
|
||||
working_folder: eng.working_folder,
|
||||
};
|
||||
|
||||
|
||||
thread::spawn(move || {
|
||||
working_thread(thread_param);
|
||||
match working_thread(&thread_param) {
|
||||
Err(_) => clean_thread(&thread_param),
|
||||
_ => {}
|
||||
};
|
||||
});
|
||||
|
||||
Ok(IdeState::OPENING)
|
||||
@@ -254,20 +257,38 @@ fn fetch_sources(repo_path: &str, param: &OpenGitParam) -> Result<(), std::io::E
|
||||
}
|
||||
}
|
||||
|
||||
fn working_thread(thread_param: ThreadRunningParam) {
|
||||
let ide_folder = thread_param.ide_folder;
|
||||
let param = thread_param.param;
|
||||
fetch_sources(&format!("{}/repo", ide_folder), ¶m).unwrap();
|
||||
let mut eng = PodmanEngine::_new(thread_param.working_folder);
|
||||
let ide_id = thread_param.container.ide_id;
|
||||
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)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
eng.save().unwrap_or_default();
|
||||
// todo delete container
|
||||
fs::remove_dir_all(eng.working_folder).unwrap_or_default();
|
||||
}
|
||||
|
||||
fn working_thread(thread_param: &ThreadRunningParam) -> Result<(), Error> {
|
||||
let ide_folder = &thread_param.ide_folder;
|
||||
let param = &thread_param.param;
|
||||
fetch_sources(&format!("{}/repo", ide_folder), ¶m).map_err(|_| Error {})?;
|
||||
let mut eng = PodmanEngine::_new(thread_param.working_folder.clone());
|
||||
let ide_id = &thread_param.container.ide_id;
|
||||
match eng.find_mut_first_container(&ide_id) {
|
||||
Some(i) => {
|
||||
i.state = PodmanState::StartingContainer;
|
||||
eng.save().unwrap();
|
||||
eng.save().map_err(|_| Error {})?;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fetch_sources() {
|
||||
let now = std::time::SystemTime::now()
|
||||
|
||||
Reference in New Issue
Block a user