Skip to content

Commit

Permalink
test: fix failing TestGenerateSSHKey on Windows
Browse files Browse the repository at this point in the history
Windows does not allow removing an open file. We need to close all open
file descriptors before we delete them.

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee authored and praveenkumar committed Nov 3, 2022
1 parent fa9e605 commit 5847f99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/crc/ssh/keys_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro
if err != nil {
return ErrUnableToWriteFile
}
defer f.Close()

if _, err := f.Write(v.Value); err != nil {
return ErrUnableToWriteFile
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/ssh/keys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro
if err != nil {
return ErrUnableToWriteFile
}
defer f.Close()

if _, err := f.Write(v.Value); err != nil {
return ErrUnableToWriteFile
Expand All @@ -37,7 +38,6 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro
if err := acl.Chmod(v.File, 0600); err != nil {
return err
}

}

return nil
Expand Down

0 comments on commit 5847f99

Please sign in to comment.