Skip to content

Commit

Permalink
Fix empty file when using compose config in case of smaller source files
Browse files Browse the repository at this point in the history
"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 #10121

Signed-off-by: Ákos Takács <takacs.akos@it-sziget.hu>
  • Loading branch information
rimelek authored and ndeloof committed Dec 30, 2022
1 parent 1d9657a commit ffce33e
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions cmd/compose/convert.go
Expand Up @@ -17,11 +17,9 @@
package compose

import (
"bufio"
"bytes"
"context"
"fmt"
"io"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit ffce33e

Please sign in to comment.