Skip to content

Commit

Permalink
Check errors of the Close call
Browse files Browse the repository at this point in the history
Error from out.Close() was not checked
  • Loading branch information
ash2k committed Nov 24, 2020
1 parent 9e360eb commit f9b928f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions staging/src/k8s.io/client-go/tools/clientcmd/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package clientcmd

import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -282,20 +281,15 @@ func (rules *ClientConfigLoadingRules) Migrate() error {
return fmt.Errorf("cannot migrate %v to %v because it is a directory", source, destination)
}

in, err := os.Open(source)
data, err := ioutil.ReadFile(source)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(destination)
// destination is created with mode 0666 before umask
err = ioutil.WriteFile(destination, data, 0666)
if err != nil {
return err
}
defer out.Close()

if _, err = io.Copy(out, in); err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit f9b928f

Please sign in to comment.