plumbed through child add/delete subcommands
This commit is contained in:
@@ -2,18 +2,20 @@ package allowances
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"mcquay.me/fs"
|
||||
)
|
||||
|
||||
var dbMutex sync.RWMutex
|
||||
|
||||
func GetHashes(filename string) (Passes, bool, error) {
|
||||
r := []string{}
|
||||
exists := false
|
||||
if !Exists(filename) {
|
||||
if !fs.Exists(filename) {
|
||||
return r, exists, nil
|
||||
}
|
||||
exists = true
|
||||
@@ -59,30 +61,3 @@ func (p Passes) Check(attempt string) (bool, error) {
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
var dbMutex = sync.RWMutex{}
|
||||
|
||||
func loadChildren(filename string) (children map[string]int) {
|
||||
dbMutex.RLock()
|
||||
defer dbMutex.RUnlock()
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = json.Unmarshal(b, &children)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func dumpChildren(filename string, children map[string]int) {
|
||||
dbMutex.Lock()
|
||||
defer dbMutex.Unlock()
|
||||
b, err := json.Marshal(children)
|
||||
err = ioutil.WriteFile(filename, b, 0644)
|
||||
if err != nil {
|
||||
log.Fatal("serious issue writing children db file", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user