Skip to content

Commit

Permalink
Merge pull request #29 from Burning1020/debug-log
Browse files Browse the repository at this point in the history
sandbox: remove sandbox dir if fail to create
  • Loading branch information
abel-von authored Mar 30, 2024
2 parents 46e401d + 911e917 commit 5f2edcf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/sandbox/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::{debug, info};
use log::{debug, info, warn};
use prost_types::Timestamp;
use time::OffsetDateTime;
use tokio::fs::{create_dir_all, remove_dir_all};
Expand Down Expand Up @@ -54,8 +54,13 @@ where
}
let base_dir = format!("{}/{}", self.dir, sandbox_data.id);
create_dir_all(&*base_dir).await?;
let opt = SandboxOption::new(base_dir, sandbox_data);
self.sandboxer.create(&*req.sandbox_id, opt).await?;
let opt = SandboxOption::new(base_dir.clone(), sandbox_data);
if let Err(e) = self.sandboxer.create(&*req.sandbox_id, opt).await {
if let Err(re) = remove_dir_all(base_dir).await {
warn!("roll back in sandbox create rmdir: {}", re);
}
return Err(e.into());
}
let resp = ControllerCreateResponse {
sandbox_id: req.sandbox_id.to_string(),
};
Expand Down

0 comments on commit 5f2edcf

Please sign in to comment.