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 (
"fmt"
"io"
"io/ioutil"
"os"
"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)
}
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