Skip to content

Commit ffce33e

Browse files
rimelekndeloof
authored andcommitted
Fix empty file when using compose config in case of smaller source files
"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 docker#10121 Signed-off-by: Ákos Takács <[email protected]>
1 parent 1d9657a commit ffce33e

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

cmd/compose/convert.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
package compose
1818

1919
import (
20-
"bufio"
2120
"bytes"
2221
"context"
2322
"fmt"
24-
"io"
2523
"os"
2624
"sort"
2725
"strings"
@@ -139,15 +137,10 @@ func runConvert(ctx context.Context, streams api.Streams, backend api.Service, o
139137
return nil
140138
}
141139

142-
var out io.Writer = streams.Out()
143140
if opts.Output != "" && len(content) > 0 {
144-
file, err := os.Create(opts.Output)
145-
if err != nil {
146-
return err
147-
}
148-
out = bufio.NewWriter(file)
141+
return os.WriteFile(opts.Output, content, 0o666)
149142
}
150-
_, err = fmt.Fprint(out, string(content))
143+
_, err = fmt.Fprint(streams.Out(), string(content))
151144
return err
152145
}
153146

0 commit comments

Comments
 (0)