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 <me@samuelkarp.com>
This commit is contained in:
Samuel Karp 2022-06-09 14:31:21 -07:00
parent 95f1d79718
commit 5560b622d6
No known key found for this signature in database
GPG Key ID: AAA3FE8A831FC087

View File

@ -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)
}