diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-09-11 12:09:34 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-09-11 12:09:34 +0200 |
commit | 31894509d503df68be49b244b55d8f97311d76ed (patch) | |
tree | ff078638f85d7a70287e51350eed353707e22ba0 /tools/updater/manifest.go | |
parent | Update golang updater tool (diff) | |
download | smolbote-31894509d503df68be49b244b55d8f97311d76ed.tar.xz |
Updater: add --dry-run parameter
- go fmt pass
Diffstat (limited to 'tools/updater/manifest.go')
-rw-r--r-- | tools/updater/manifest.go | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/tools/updater/manifest.go b/tools/updater/manifest.go index 942a5e7..0d8bfae 100644 --- a/tools/updater/manifest.go +++ b/tools/updater/manifest.go @@ -1,41 +1,41 @@ package main import ( - "crypto/sha512" - "os" - "io" - "fmt" + "crypto/sha512" + "fmt" + "io" + "os" ) func checkFile(filepath string, checksum string) (bool, error) { - if _, err := os.Stat(filepath); os.IsNotExist(err) { - return false, nil - } + if _, err := os.Stat(filepath); os.IsNotExist(err) { + return false, nil + } - // file exists, check checksum - lsum, err := hash(filepath) - if err != nil { - return false, err - } + // file exists, check checksum + lsum, err := hash(filepath) + if err != nil { + return false, err + } - if checksum != fmt.Sprintf("%x", lsum) { - return false, nil - } + if checksum != fmt.Sprintf("%x", lsum) { + return false, nil + } - return true, nil + return true, nil } func hash(filepath string) ([]byte, error) { - file, err := os.Open(filepath) - if err != nil { - return nil, err - } - defer file.Close() - - hasher := sha512.New() - if _, err := io.Copy(hasher, file); err != nil { - return nil, err - } - - return hasher.Sum(nil), nil + file, err := os.Open(filepath) + if err != nil { + return nil, err + } + defer file.Close() + + hasher := sha512.New() + if _, err := io.Copy(hasher, file); err != nil { + return nil, err + } + + return hasher.Sum(nil), nil } |