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