File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -311,7 +311,7 @@ func configSSH() *cobra.Command {
311
311
// directory as path and renames the temp file to the file provided in
312
312
// path. This ensure we avoid trashing the file we are writing due to
313
313
// unforeseen circumstance like filesystem full, command killed, etc.
314
- func writeWithTempFileAndMove (path string , r io.Reader ) error {
314
+ func writeWithTempFileAndMove (path string , r io.Reader ) ( err error ) {
315
315
dir := filepath .Dir (path )
316
316
name := filepath .Base (path )
317
317
@@ -321,6 +321,11 @@ func writeWithTempFileAndMove(path string, r io.Reader) error {
321
321
if err != nil {
322
322
return xerrors .Errorf ("create temp file failed: %w" , err )
323
323
}
324
+ defer func () {
325
+ if err != nil {
326
+ _ = os .Remove (f .Name ()) // Cleanup in case a step failed.
327
+ }
328
+ }()
324
329
325
330
_ , err = io .Copy (f , r )
326
331
if err != nil {
You can’t perform that action at this time.
0 commit comments