summaryrefslogtreecommitdiffstats
path: root/db/db.go
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-11-28 17:03:18 -0500
committersiddharth <s@ricketyspace.net>2021-11-28 17:03:18 -0500
commit337741015cc46179fa8886079a416bb2fe4f4845 (patch)
tree0e914f58f1a86b2fb9951eadecfa75e7491c3314 /db/db.go
parent8adac927363d1f541b0737c96c713cd6d79acb79 (diff)
db: update FernDB
Add `mutex` field to the FernDB struct.
Diffstat (limited to 'db/db.go')
-rw-r--r--db/db.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/db/db.go b/db/db.go
index 2d6a4d5..6bc6d04 100644
--- a/db/db.go
+++ b/db/db.go
@@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path"
+ "sync"
"ricketyspace.net/fern/file"
)
@@ -15,6 +16,7 @@ import (
var dbPath string
type FernDB struct {
+ mutex *sync.Mutex // For writes to `downloaded`
// Key: feed-id
// Value: feed-id's entries that were downloaded
downloaded map[string][]string
@@ -42,6 +44,7 @@ func Open() (*FernDB, error) {
if err != nil {
// db does not exist yet; create an empty one.
db := new(FernDB)
+ db.mutex = new(sync.Mutex)
db.downloaded = make(map[string][]string)
return db, nil
}
@@ -58,6 +61,7 @@ func Open() (*FernDB, error) {
// Unmarshal db into an object.
db := new(FernDB)
+ db.mutex = new(sync.Mutex)
err = json.Unmarshal(bs, &db.downloaded)
if err != nil {
return nil, err