Only open save output file with WRONLY

The previous code fails on a MAC when opening /dev/stdout

Fixes: https://github.com/containers/podman/issues/12402

[NO NEW TESTS NEEDED] No easy way to test this.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2021-11-24 10:34:16 -05:00
parent 6052914222
commit 931c08157e
No known key found for this signature in database
GPG Key ID: A2DF901DABE2C028
1 changed files with 4 additions and 1 deletions

View File

@ -270,7 +270,10 @@ func (ir *ImageEngine) Save(ctx context.Context, nameOrID string, tags []string,
defer func() { _ = os.Remove(f.Name()) }()
}
default:
f, err = os.Create(opts.Output)
// This code was added to allow for opening stdout replacing
// os.Create(opts.Output) which was attempting to open the file
// for read/write which fails on Darwin platforms
f, err = os.OpenFile(opts.Output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
}
if err != nil {
return err