File tree Expand file tree Collapse file tree 1 file changed +7
-21
lines changed
Expand file tree Collapse file tree 1 file changed +7
-21
lines changed Original file line number Diff line number Diff line change @@ -17,37 +17,23 @@ import (
1717 "github.com/docker/cli/cli/streams"
1818 "github.com/docker/docker/api/types/filters"
1919 "github.com/docker/docker/errdefs"
20- "github.com/moby/sys/sequential "
20+ "github.com/docker/docker/pkg/atomicwriter "
2121 "github.com/moby/term"
2222 "github.com/pkg/errors"
2323 "github.com/spf13/pflag"
2424)
2525
2626// CopyToFile writes the content of the reader to the specified file
27+ //
28+ // Deprecated: use [atomicwriter.New].
2729func CopyToFile (outfile string , r io.Reader ) error {
28- // We use sequential file access here to avoid depleting the standby list
29- // on Windows. On Linux, this is a call directly to os.CreateTemp
30- tmpFile , err := sequential .CreateTemp (filepath .Dir (outfile ), ".docker_temp_" )
31- if err != nil {
32- return err
33- }
34-
35- tmpPath := tmpFile .Name ()
36-
37- _ , err = io .Copy (tmpFile , r )
38- tmpFile .Close ()
39-
30+ writer , err := atomicwriter .New (outfile , 0o600 )
4031 if err != nil {
41- os .Remove (tmpPath )
42- return err
43- }
44-
45- if err = os .Rename (tmpPath , outfile ); err != nil {
46- os .Remove (tmpPath )
4732 return err
4833 }
49-
50- return nil
34+ defer writer .Close ()
35+ _ , err = io .Copy (writer , r )
36+ return err
5137}
5238
5339var ErrPromptTerminated = errdefs .Cancelled (errors .New ("prompt terminated" ))
You can’t perform that action at this time.
0 commit comments