From ffce33ec1167281160f08014000d9d5b5b9a2e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81kos=20Tak=C3=A1cs?= Date: Thu, 29 Dec 2022 22:29:59 +0100 Subject: [PATCH] Fix empty file when using compose config in case of smaller source files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "docker compose config --output out.yml" resulted an empty file when the generated output was smaller than 4097 bytes. bufio.Writer doesn't seem necessary since only one write operation will happen. This way there is no need for a new bufio.Writer that could be flushed. Thanks for @thaJeztah for the idea of using os.WriteFile Issue https://github.com/docker/compose/issues/10121 Signed-off-by: Ákos Takács --- cmd/compose/convert.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cmd/compose/convert.go b/cmd/compose/convert.go index e1d5c5930..29d22c07b 100644 --- a/cmd/compose/convert.go +++ b/cmd/compose/convert.go @@ -17,11 +17,9 @@ package compose import ( - "bufio" "bytes" "context" "fmt" - "io" "os" "sort" "strings" @@ -139,15 +137,10 @@ func runConvert(ctx context.Context, streams api.Streams, backend api.Service, o return nil } - var out io.Writer = streams.Out() if opts.Output != "" && len(content) > 0 { - file, err := os.Create(opts.Output) - if err != nil { - return err - } - out = bufio.NewWriter(file) + return os.WriteFile(opts.Output, content, 0o666) } - _, err = fmt.Fprint(out, string(content)) + _, err = fmt.Fprint(streams.Out(), string(content)) return err }