Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/moby/buildkit v0.20.1
github.com/moby/patternmatcher v0.6.0
github.com/moby/sys/atomicwriter v0.1.0
github.com/moby/term v0.5.2
github.com/morikuni/aec v1.0.0
github.com/opencontainers/go-digest v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkV
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/spdystream v0.4.0 h1:Vy79D6mHeJJjiPdFEL2yku1kl0chZpJfZcPpb16BRl8=
github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=
github.com/moby/sys/capability v0.4.0 h1:4D4mI6KlNtWMCM1Z/K0i7RV1FkX+DBDHKVJpCndZoHk=
github.com/moby/sys/capability v0.4.0/go.mod h1:4g9IK291rVkms3LKCDOoYlnV8xKwoDTpIrNEE35Wq0I=
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
Expand Down
22 changes: 14 additions & 8 deletions pkg/compose/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
"github.com/moby/sys/atomicwriter"
)

func (s *composeService) Export(ctx context.Context, projectName string, options api.ExportOptions) error {
Expand All @@ -41,11 +42,11 @@ func (s *composeService) export(ctx context.Context, projectName string, options
return err
}

if options.Output == "" && s.dockerCli.Out().IsTerminal() {
return fmt.Errorf("output option is required when exporting to terminal")
}

if err := command.ValidateOutputPath(options.Output); err != nil {
if options.Output == "" {
if s.dockerCli.Out().IsTerminal() {
return fmt.Errorf("output option is required when exporting to terminal")
}
} else if err := command.ValidateOutputPath(options.Output); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW; atomicwriter.New() also performs this validation, so we could have a look if we still need this check before we run that code 🤔

I should also have a look at; the copy commands;

compose/pkg/compose/cp.go

Lines 174 to 177 in a1f673d

// Validate the destination path
if err := command.ValidateOutputPathFileMode(dstStat.Mode); err != nil {
return fmt.Errorf(`destination "%s:%s" must be a directory or a regular file: %w`, containerID, dstPath, err)
}

compose/pkg/compose/cp.go

Lines 255 to 257 in a1f673d

if err := command.ValidateOutputPath(dstPath); err != nil {
return err
}

return fmt.Errorf("failed to export container: %w", err)
}

Expand Down Expand Up @@ -83,9 +84,14 @@ func (s *composeService) export(ctx context.Context, projectName string, options
if options.Output == "" {
_, err := io.Copy(s.dockerCli.Out(), responseBody)
return err
}

if err := command.CopyToFile(options.Output, responseBody); err != nil {
} else {
writer, err := atomicwriter.New(options.Output, 0o600)
if err != nil {
return err
}
defer func() { _ = writer.Close() }()

_, err = io.Copy(writer, responseBody)
return err
}
}
Expand Down