From aca993632f7bbe8034234beba2855dd2d95ff16c Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 27 Apr 2023 11:52:59 +0200 Subject: [PATCH] windows: podman save allow the use of stdout By default podman save tries to write to /dev/stdout, this file doe snot exists on windows and cannot be opened. Instead we should just use fd 1 in such case. [NO NEW TESTS NEEDED] Fixes #18147 Signed-off-by: Paul Holzinger --- pkg/domain/infra/tunnel/images.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go index 0d92a53098..a05909b307 100644 --- a/pkg/domain/infra/tunnel/images.go +++ b/pkg/domain/infra/tunnel/images.go @@ -282,10 +282,19 @@ func (ir *ImageEngine) Save(ctx context.Context, nameOrID string, tags []string, defer func() { _ = os.Remove(f.Name()) }() } default: - // 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) + // This is ugly but I think the best we can do for now, + // on windows there is no /dev/stdout but the save command defaults to /dev/stdout. + // The proper thing to do would be to pass an io.Writer down from the cli frontend + // but since the local save API does not support an io.Writer this is impossible. + // I reported it a while ago in https://github.com/containers/common/issues/1275 + if opts.Output == "/dev/stdout" { + f = os.Stdout + } else { + // 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