From 55f8ec8abf53dc868bc1f90eeb9b1f04763c69dd Mon Sep 17 00:00:00 2001 From: fengwei0328 Date: Fri, 22 Nov 2024 14:26:37 +0800 Subject: [PATCH] The task_dir successfully cleans when the file is absent Signed-off-by: fengwei0328 --- crates/runc-shim/src/service.rs | 6 ++++-- crates/shim/src/asynchronous/util.rs | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/runc-shim/src/service.rs b/crates/runc-shim/src/service.rs index 85e280e3..d8a7b3ba 100644 --- a/crates/runc-shim/src/service.rs +++ b/crates/runc-shim/src/service.rs @@ -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, @@ -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 diff --git a/crates/shim/src/asynchronous/util.rs b/crates/shim/src/asynchronous/util.rs index 43e2b88d..f90b9f1c 100644 --- a/crates/shim/src/asynchronous/util.rs +++ b/crates/shim/src/asynchronous/util.rs @@ -101,6 +101,9 @@ pub async fn read_spec(bundle: impl AsRef) -> Result { pub async fn read_options(bundle: impl AsRef) -> Result { 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::(&opts_str).map_err(other_error!("read options"))?;