mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 11:44:26 -06:00
062d255124
* replace ioutil.ReadFile -> os.ReadFile * replace ioutil.ReadAll -> io.ReadAll * replace ioutil.TempFile -> os.CreateTemp * replace ioutil.NopCloser -> io.NopCloser * replace ioutil.WriteFile -> os.WriteFile * replace ioutil.TempDir -> os.MkdirTemp * replace ioutil.Discard -> io.Discard
36 lines
626 B
Go
36 lines
626 B
Go
package cryptoutil
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func MD5File(fpath string) error {
|
|
// Ignore gosec G304 as this function is only used in the build process.
|
|
//nolint:gosec
|
|
fd, err := os.Open(fpath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
if err := fd.Close(); err != nil {
|
|
log.Printf("error closing file at '%s': %s", fpath, err.Error())
|
|
}
|
|
}()
|
|
|
|
h := md5.New() // nolint:gosec
|
|
if _, err = io.Copy(h, fd); err != nil {
|
|
return err
|
|
}
|
|
|
|
// nolint:gosec
|
|
if err := os.WriteFile(fpath+".md5", []byte(fmt.Sprintf("%x\n", h.Sum(nil))), 0664); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|