From 40c406506b875b70ada9ec8c423452c5371205ee Mon Sep 17 00:00:00 2001 From: stevenhorsman Date: Wed, 15 Sep 2021 18:04:41 +0100 Subject: [PATCH] agent: Add CreateContainer support for pre-pulled bundle - Add a check in setup_bundle to see if the bundle already exists and if it does then skip the setup. Fixes: #2617 Co-authored-by: Dave Hay Signed-off-by: stevenhorsman --- src/agent/src/rpc.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index 18e072bd64..880bd55c25 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -1653,20 +1653,27 @@ fn setup_bundle(cid: &str, spec: &mut Spec) -> Result { let config_path = bundle_path.join("config.json"); let rootfs_path = bundle_path.join("rootfs"); - fs::create_dir_all(&rootfs_path)?; - baremount( - &spec_root.path, - rootfs_path.to_str().unwrap(), - "bind", - MsFlags::MS_BIND, - "", - &sl!(), - )?; + let rootfs_exists = Path::new(&rootfs_path).exists(); + info!( + sl!(), + "The rootfs_path is {:?} and exists: {}", rootfs_path, rootfs_exists + ); + + if !rootfs_exists { + fs::create_dir_all(&rootfs_path)?; + baremount( + &spec_root.path, + rootfs_path.to_str().unwrap(), + "bind", + MsFlags::MS_BIND, + "", + &sl!(), + )?; + } spec.root = Some(Root { path: rootfs_path.to_str().unwrap().to_owned(), readonly: spec_root.readonly, }); - let _ = spec.save(config_path.to_str().unwrap()); let olddir = unistd::getcwd().context("cannot getcwd")?;