MCPcopy Create free account
hub / github.com/bootc-dev/bootc / create

Method create

crates/lib/src/podstorage.rs:287–333  ·  view source on GitHub ↗
(
        sysroot: &Dir,
        run: &Dir,
        sepolicy: Option<&ostree::SePolicy>,
    )

Source from the content-addressed store, hash-verified

285
286 #[context("Creating imgstorage")]
287 pub(crate) fn create(
288 sysroot: &Dir,
289 run: &Dir,
290 sepolicy: Option<&ostree::SePolicy>,
291 ) -> Result<Self> {
292 Self::init_globals()?;
293 let subpath = &Self::subpath();
294
295 // SAFETY: We know there's a parent
296 let parent = subpath.parent().unwrap();
297 let tmp = format!("{subpath}.tmp");
298 let existed = sysroot
299 .try_exists(subpath)
300 .with_context(|| format!("Querying {subpath}"))?;
301 if !existed {
302 sysroot.remove_all_optional(&tmp).context("Removing tmp")?;
303 sysroot
304 .create_dir_all(parent)
305 .with_context(|| format!("Creating {parent}"))?;
306 sysroot.create_dir_all(&tmp).context("Creating tmpdir")?;
307 let storage_root = sysroot.open_dir(&tmp).context("Open tmp")?;
308
309 // There's no explicit API to initialize a containers-storage:
310 // root, simply passing a path will attempt to auto-create it.
311 // We run "podman images" in the new root.
312 new_podman_cmd_in(&sysroot, &storage_root, &run)?
313 .stdout(Stdio::null())
314 .arg("images")
315 .run_capture_stderr()
316 .context("Initializing images")?;
317 drop(storage_root);
318 sysroot
319 .rename(&tmp, sysroot, subpath)
320 .context("Renaming tmpdir")?;
321 tracing::debug!("Created image store");
322 }
323
324 let s = Self::open(sysroot, run, sepolicy.cloned())?;
325 if existed {
326 // For pre-existing storage (e.g. on a booted system), ensure
327 // labels are correct now. For freshly created storage (e.g.
328 // during install), labeling is deferred until after all image
329 // pulls are complete via an explicit ensure_labeled() call.
330 s.ensure_labeled()?;
331 }
332 Ok(s)
333 }
334
335 #[context("Opening imgstorage")]
336 pub(crate) fn open(

Callers 5

ensure_labeledMethod · 0.80
runFunction · 0.80
generate_oneFunction · 0.80
export_tarMethod · 0.80
test_tar_import_signedFunction · 0.80

Calls 4

new_podman_cmd_inFunction · 0.85
run_capture_stderrMethod · 0.80
argMethod · 0.80
ensure_labeledMethod · 0.80

Tested by 1

test_tar_import_signedFunction · 0.64