Skip to content

Commit 04fb812

Browse files
authored
Merge pull request bootc-dev#605 from cgwalters/format-image-alternate
lib/tar: Add much more error context
2 parents 4549445 + cce81ce commit 04fb812

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/src/tar/write.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
1414
use cap_std::io_lifetimes;
1515
use cap_std_ext::cmdext::CapStdExtCommandExt;
1616
use cap_std_ext::{cap_std, cap_tempfile};
17+
use fn_error_context::context;
1718
use once_cell::unsync::OnceCell;
1819
use ostree::gio;
1920
use ostree::prelude::FileExt;
@@ -31,6 +32,7 @@ use tracing::instrument;
3132
const EXCLUDED_TOPLEVEL_PATHS: &[&str] = &["run", "tmp", "proc", "sys", "dev"];
3233

3334
/// Copy a tar entry to a new tar archive, optionally using a different filesystem path.
35+
#[context("Copying entry")]
3436
pub(crate) fn copy_entry(
3537
entry: tar::Entry<impl std::io::Read>,
3638
dest: &mut tar::Builder<impl std::io::Write>,
@@ -227,18 +229,23 @@ pub(crate) fn filter_tar(
227229
if is_modified && is_regular {
228230
tracing::debug!("Processing modified sysroot file {path}");
229231
// Lazily allocate a temporary directory
230-
let tmpdir = tmpdir.get_or_try_init(|| {
232+
let tmpdir = tmpdir.get_or_try_init(|| -> anyhow::Result<_> {
231233
let vartmp = &cap_std::fs::Dir::open_ambient_dir(
232234
"/var/tmp",
233235
cap_std::ambient_authority(),
234-
)?;
235-
cap_tempfile::tempdir_in(vartmp)
236+
)
237+
.context("Allocating tmpdir")?;
238+
cap_tempfile::tempdir_in(vartmp).map_err(anyhow::Error::msg)
236239
})?;
237240
// Create an O_TMPFILE (anonymous file) to use as a temporary store for the file data
238-
let mut tmpf = cap_tempfile::TempFile::new_anonymous(tmpdir).map(BufWriter::new)?;
241+
let mut tmpf = cap_tempfile::TempFile::new_anonymous(tmpdir)
242+
.map(BufWriter::new)
243+
.context("Creating tmpfile")?;
239244
let path = path.to_owned();
240245
let header = header.clone();
241-
std::io::copy(&mut entry, &mut tmpf)?;
246+
std::io::copy(&mut entry, &mut tmpf)
247+
.map_err(anyhow::Error::msg)
248+
.context("Copying")?;
242249
let mut tmpf = tmpf.into_inner()?;
243250
tmpf.seek(std::io::SeekFrom::Start(0))?;
244251
// Cache this data, indexed by the file path
@@ -292,6 +299,7 @@ pub(crate) fn filter_tar(
292299
}
293300

294301
/// Asynchronous wrapper for filter_tar()
302+
#[context("Filtering tar stream")]
295303
async fn filter_tar_async(
296304
src: impl AsyncRead + Send + 'static,
297305
mut dest: impl AsyncWrite + Send + Unpin,
@@ -405,7 +413,7 @@ pub async fn write_tar(
405413
};
406414
tracing::debug!("Waiting on child process");
407415
let (filtered_result, child_stdout) =
408-
match tokio::try_join!(status, filtered_result).context("Processing tar via ostree") {
416+
match tokio::try_join!(status, filtered_result).context("Processing tar") {
409417
Ok(((), filtered_result)) => {
410418
let (child_stdout, _) = output_copier.await.context("Copying child output")?;
411419
(filtered_result, child_stdout)

0 commit comments

Comments
 (0)