| 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( |