From 5560b622d6e952213380eec7936af6a580d0c17b Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Thu, 9 Jun 2022 14:31:21 -0700 Subject: [PATCH] archive: Explicitly specify stdio for tar(1) Different tar(1) implementations default to different input and output locations when none is specified. This can include tape devices like /dev/st0 (on Linux) or /dev/sa0 (on FreeBSD), but may be overridden by compilation options or environment variables. Using the f option with the special value of - instructs tar(1) to read from stdin and write to stdout instead of the default. Signed-off-by: Samuel Karp --- archive/tar_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archive/tar_test.go b/archive/tar_test.go index 3ffb697cb..ba2179c22 100644 --- a/archive/tar_test.go +++ b/archive/tar_test.go @@ -844,7 +844,7 @@ func testApply(t *testing.T, a fstest.Applier) error { return fmt.Errorf("failed to apply filesystem changes: %w", err) } - tarArgs := []string{"c", "-C", td} + tarArgs := []string{"cf", "-", "-C", td} names, err := readDirNames(td) if err != nil { return fmt.Errorf("failed to read directory names: %w", err) @@ -879,9 +879,12 @@ func testBaseDiff(t *testing.T, a fstest.Applier) error { arch := Diff(context.Background(), "", td) - cmd := exec.Command(tarCmd, "x", "-C", dest) + cmd := exec.Command(tarCmd, "xf", "-", "-C", dest) cmd.Stdin = arch + stderr := &bytes.Buffer{} + cmd.Stderr = stderr if err := cmd.Run(); err != nil { + fmt.Println(stderr.String()) return fmt.Errorf("tar command failed: %w", err) }