@@ -71,17 +71,27 @@ func (d *DirectDownloadInstaller) Install(tool *registry.Tool, p platform.Platfo
7171 }
7272
7373 destPath := filepath .Join (destDir , tool .BinaryName )
74- f , err := os .Create ( destPath )
74+ tmp , err := os .CreateTemp ( destDir , ".cps-tmp-*" )
7575 if err != nil {
7676 return Result {Tool : tool .Name , Err : err }
7777 }
78- defer f . Close ()
78+ tmpPath := tmp . Name ()
7979
80- if _ , err := io .Copy (f , resp .Body ); err != nil {
80+ if _ , err := io .Copy (tmp , resp .Body ); err != nil {
81+ tmp .Close ()
82+ os .Remove (tmpPath )
8183 return Result {Tool : tool .Name , Err : err }
8284 }
83-
84- if err := os .Chmod (destPath , 0755 ); err != nil {
85+ if err := tmp .Close (); err != nil {
86+ os .Remove (tmpPath )
87+ return Result {Tool : tool .Name , Err : err }
88+ }
89+ if err := os .Chmod (tmpPath , 0755 ); err != nil {
90+ os .Remove (tmpPath )
91+ return Result {Tool : tool .Name , Err : err }
92+ }
93+ if err := os .Rename (tmpPath , destPath ); err != nil {
94+ os .Remove (tmpPath )
8595 return Result {Tool : tool .Name , Err : err }
8696 }
8797
@@ -157,11 +167,7 @@ func (d *DirectDownloadInstaller) installArchive(tool *registry.Tool, url, versi
157167 }
158168
159169 destPath := filepath .Join (destDir , tool .BinaryName )
160- data , err := os .ReadFile (binaryPath )
161- if err != nil {
162- return Result {Tool : tool .Name , Err : err }
163- }
164- if err := os .WriteFile (destPath , data , 0755 ); err != nil {
170+ if err := AtomicInstallBinary (binaryPath , destPath ); err != nil {
165171 return Result {Tool : tool .Name , Err : err }
166172 }
167173
0 commit comments