Implemented GetImportsSHA1List & UpdateImportsSHA1List

This commit is contained in:
マリウス 2020-10-16 00:58:56 +01:00
parent 3cd421ef8b
commit 1e053c1123
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -3,6 +3,7 @@ package z
import ( import (
"os" "os"
"sort" "sort"
"strings"
"log" "log"
"errors" "errors"
"encoding/json" "encoding/json"
@ -151,3 +152,48 @@ func (database *Database) ListEntries(user string) ([]Entry, error) {
sort.Slice(entries, func(i, j int) bool { return entries[i].Begin.Before(entries[j].Begin) }) sort.Slice(entries, func(i, j int) bool { return entries[i].Begin.Before(entries[j].Begin) })
return entries, dberr return entries, dberr
} }
func (database *Database) GetImportsSHA1List(user string) (map[string]string, error) {
var sha1List = make(map[string]string)
dberr := database.DB.View(func(tx *buntdb.Tx) error {
value, err := tx.Get(user + ":imports:sha1", false)
if err != nil {
return nil
}
sha1Entries := strings.Split(value, ",")
for _, sha1Entry := range sha1Entries {
sha1EntrySplit := strings.Split(sha1Entry, ":")
sha1 := sha1EntrySplit[0]
id := sha1EntrySplit[1]
sha1List[sha1] = id
}
return nil
})
return sha1List, dberr
}
func (database *Database) UpdateImportsSHA1List(user string, sha1List map[string]string) (error) {
var sha1Entries []string
for sha1, id := range sha1List {
sha1Entries = append(sha1Entries, sha1 + ":" + id)
}
value := strings.Join(sha1Entries, ",")
dberr := database.DB.Update(func(tx *buntdb.Tx) error {
_, _, seterr := tx.Set(user + ":imports:sha1", value, nil)
if seterr != nil {
return seterr
}
return nil
})
return dberr
}