Skip to content

Commit

Permalink
The task_dir successfully cleans when the file is absent
Browse files Browse the repository at this point in the history
Signed-off-by: fengwei0328 <[email protected]>
  • Loading branch information
fengwei0328 committed Nov 27, 2024
1 parent 6d496ef commit 55f8ec8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/runc-shim/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Shim for Service {
let namespace = self.namespace.as_str();
let bundle = current_dir().map_err(io_error!(e, "get current dir"))?;
let opts = read_options(&bundle).await?;
let runtime = read_runtime(&bundle).await?;
let runtime = read_runtime(&bundle).await.unwrap_or_default();

let runc = create_runc(
&runtime,
Expand All @@ -117,7 +117,9 @@ impl Shim for Service {
&opts,
Some(Arc::new(ShimExecutor::default())),
)?;
let pid = read_pid_from_file(&bundle.join(INIT_PID_FILE)).await?;
let pid = read_pid_from_file(&bundle.join(INIT_PID_FILE))
.await
.unwrap_or_default();

runc.delete(&self.id, Some(&DeleteOpts { force: true }))
.await
Expand Down
3 changes: 3 additions & 0 deletions crates/shim/src/asynchronous/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ pub async fn read_spec(bundle: impl AsRef<Path>) -> Result<Spec> {

pub async fn read_options(bundle: impl AsRef<Path>) -> Result<Options> {
let path = bundle.as_ref().join(OPTIONS_FILE_NAME);
if !path.exists() {
return Ok(Options::default());
}
let opts_str = read_file_to_str(path).await?;
let opts =
serde_json::from_str::<JsonOptions>(&opts_str).map_err(other_error!("read options"))?;
Expand Down

0 comments on commit 55f8ec8

Please sign in to comment.