File tree 1 file changed +7
-21
lines changed
1 file changed +7
-21
lines changed Original file line number Diff line number Diff line change @@ -19,37 +19,23 @@ import (
19
19
mounttypes "github.com/docker/docker/api/types/mount"
20
20
"github.com/docker/docker/api/types/versions"
21
21
"github.com/docker/docker/errdefs"
22
- "github.com/moby/sys/sequential "
22
+ "github.com/docker/docker/pkg/atomicwriter "
23
23
"github.com/moby/term"
24
24
"github.com/pkg/errors"
25
25
"github.com/spf13/pflag"
26
26
)
27
27
28
28
// CopyToFile writes the content of the reader to the specified file
29
+ //
30
+ // Deprecated: use [atomicwriter.New].
29
31
func CopyToFile (outfile string , r io.Reader ) error {
30
- // We use sequential file access here to avoid depleting the standby list
31
- // on Windows. On Linux, this is a call directly to os.CreateTemp
32
- tmpFile , err := sequential .CreateTemp (filepath .Dir (outfile ), ".docker_temp_" )
33
- if err != nil {
34
- return err
35
- }
36
-
37
- tmpPath := tmpFile .Name ()
38
-
39
- _ , err = io .Copy (tmpFile , r )
40
- tmpFile .Close ()
41
-
32
+ writer , err := atomicwriter .New (outfile , 0o600 )
42
33
if err != nil {
43
- os .Remove (tmpPath )
44
- return err
45
- }
46
-
47
- if err = os .Rename (tmpPath , outfile ); err != nil {
48
- os .Remove (tmpPath )
49
34
return err
50
35
}
51
-
52
- return nil
36
+ defer writer .Close ()
37
+ _ , err = io .Copy (writer , r )
38
+ return err
53
39
}
54
40
55
41
var ErrPromptTerminated = errdefs .Cancelled (errors .New ("prompt terminated" ))
You can’t perform that action at this time.
0 commit comments