aboutsummaryrefslogtreecommitdiff
path: root/tools/updater/manifest.go
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-09-11 02:06:31 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-09-11 02:06:31 +0200
commita3d5c49e061d7b022271ea2be374e929ff385c60 (patch)
treea3346c813f8c8a39cfd825f3642dece46eca13f1 /tools/updater/manifest.go
parentWebProfile: save httpCacheType and persistentCookiesPolicy (diff)
downloadsmolbote-a3d5c49e061d7b022271ea2be374e929ff385c60.tar.xz
Update golang updater tool
Diffstat (limited to 'tools/updater/manifest.go')
-rw-r--r--tools/updater/manifest.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/updater/manifest.go b/tools/updater/manifest.go
new file mode 100644
index 0000000..942a5e7
--- /dev/null
+++ b/tools/updater/manifest.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "crypto/sha512"
+ "os"
+ "io"
+ "fmt"
+)
+
+func checkFile(filepath string, checksum string) (bool, error) {
+ 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
+ }
+
+ if checksum != fmt.Sprintf("%x", lsum) {
+ return false, 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
+}