Debian Codegraph @

config/reload.go

raw
1 package config
2
3 import (
4 "errors"
5 "os"
6 "path/filepath"
7
8 "git.sr.ht/~rjarry/aerc/lib/log"
9 )
10
11 type reloadStore struct {
12 binds string
13 conf string
14 }
15
16 var rlst reloadStore
17
18 func SetBindsFilename(fn string) {
19 log.Debugf("reloader: set binds file: %s", fn)
20 rlst.binds = fn
21 }
22
23 func SetConfFilename(fn string) {
24 log.Debugf("reloader: set conf file: %s", fn)
25 rlst.conf = fn
26 }
27
28 func ReloadBinds() (string, error) {
29 f := rlst.binds
30 if !exists(f) {
31 return f, os.ErrNotExist
32 }
33 log.Debugf("reload binds file: %s", f)
34 return f, parseBindsFromFile(filepath.Dir(f), f)
35 }
36
37 func ReloadConf() (string, error) {
38 f := rlst.conf
39 if !exists(f) {
40 return f, os.ErrNotExist
41 }
42 log.Debugf("reload conf file: %s", f)
43
44 return f, parseConf(f)
45 }
46
47 func ReloadAccounts() error {
48 return errors.New("not implemented")
49 }
50
51 func exists(fn string) bool {
52 if _, err := os.Stat(fn); errors.Is(err, os.ErrNotExist) {
53 return false
54 }
55 return true
56 }