Check errors of the Close call

Error from out.Close() was not checked
This commit is contained in:
Mikhail Mazurskiy 2020-06-15 21:47:08 +10:00
parent 9e360eb05e
commit f9b928f1f1
No known key found for this signature in database
GPG Key ID: FA7917C48932DD55

View File

@ -18,7 +18,6 @@ package clientcmd
import ( import (
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -282,20 +281,15 @@ func (rules *ClientConfigLoadingRules) Migrate() error {
return fmt.Errorf("cannot migrate %v to %v because it is a directory", source, destination) 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 { if err != nil {
return err return err
} }
defer in.Close() // destination is created with mode 0666 before umask
out, err := os.Create(destination) err = ioutil.WriteFile(destination, data, 0666)
if err != nil { if err != nil {
return err return err
} }
defer out.Close()
if _, err = io.Copy(out, in); err != nil {
return err
}
} }
return nil return nil