From daff9f81ad62b4bb0a77c3cfb511c7c93bc62d2f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 25 Jan 2024 17:27:45 -0500 Subject: [PATCH] encapsulate: Fix regression with relative directories https://github.com/ostreedev/ostree-rs-ext/pull/586/commits/b104a467e9ed06663194c3b60334a5246eb988fb broke the rpm-ostree test suite, which encapsulates to a *relative* file path and so us doing `chdir` broke it. Switch to passing down the dirfd and using `/proc/self/fd`. (Mutable global state in `chdir` is bad) --- lib/src/container/encapsulate.rs | 5 +++-- lib/src/container/skopeo.rs | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/container/encapsulate.rs b/lib/src/container/encapsulate.rs index 475bbff9..7aa9ddcf 100644 --- a/lib/src/container/encapsulate.rs +++ b/lib/src/container/encapsulate.rs @@ -319,15 +319,16 @@ async fn build_impl( drop(ocidir); // Pass the temporary oci directory as the current working directory for the skopeo process + let target_fd = 3i32; let tempoci = ImageReference { transport: Transport::OciDir, - name: ".".into(), + name: format!("/proc/self/fd/{target_fd}"), }; let digest = skopeo::copy( &tempoci, dest, authfile.as_deref(), - Some(tempdir.try_clone()?), + Some((std::sync::Arc::new(tempdir.try_clone()?.into()), target_fd)), ) .await?; Some(digest) diff --git a/lib/src/container/skopeo.rs b/lib/src/container/skopeo.rs index df247cfe..aa18333f 100644 --- a/lib/src/container/skopeo.rs +++ b/lib/src/container/skopeo.rs @@ -2,9 +2,9 @@ use super::ImageReference; use anyhow::{Context, Result}; -use cap_std_ext::cap_std::fs::Dir; use cap_std_ext::cmdext::CapStdExtCommandExt; use fn_error_context::context; +use io_lifetimes::OwnedFd; use serde::Deserialize; use std::io::Read; use std::path::Path; @@ -66,15 +66,15 @@ pub(crate) async fn copy( src: &ImageReference, dest: &ImageReference, authfile: Option<&Path>, - cwd: Option, + add_fd: Option<(std::sync::Arc, i32)>, ) -> Result { let digestfile = tempfile::NamedTempFile::new()?; let mut cmd = new_cmd(); cmd.stdout(std::process::Stdio::null()).arg("copy"); cmd.arg("--digestfile"); cmd.arg(digestfile.path()); - if let Some(cwd) = cwd { - cmd.cwd_dir(cwd); + if let Some((add_fd, n)) = add_fd { + cmd.take_fd_n(add_fd, n); } if let Some(authfile) = authfile { cmd.arg("--authfile");