Check errors of the Close call

Error from out.Close() was not checked

Kubernetes-commit: f9b928f1f13821b65ea4ef783f847993c51fb4dd
This commit is contained in:
Mikhail Mazurskiy 2020-06-15 21:47:08 +10:00 committed by Kubernetes Publisher
parent 6cc39819fd
commit 29b07456f5

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