forked from browserutils/kooky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookiestore.go
60 lines (50 loc) · 1019 Bytes
/
cookiestore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package firefox
import (
"errors"
"os"
"path/filepath"
"github.com/etng/kooky/internal/cookies"
"github.com/go-sqlite/sqlite3"
)
type CookieStore struct {
cookies.DefaultCookieStore
Database *sqlite3.DbFile
Containers map[int]string
contFile *os.File
}
var _ cookies.CookieStore = (*CookieStore)(nil)
func (s *CookieStore) Open() error {
if s == nil {
return errors.New(`cookie store is nil`)
}
if s.Database != nil {
return nil
}
db, err := sqlite3.Open(s.FileNameStr)
if err != nil {
return err
}
s.Database = db
contFileName := filepath.Join(filepath.Dir(s.FileNameStr), `containers.json`)
s.contFile, _ = os.Open(contFileName)
return nil
}
func (s *CookieStore) Close() error {
if s == nil {
return errors.New(`cookie store is nil`)
}
if s.Database == nil {
return nil
}
err := s.Database.Close()
if err == nil {
s.Database = nil
}
if s.contFile != nil {
errCont := s.contFile.Close()
if errCont != nil && err == nil {
err = errCont
}
}
return err
}