diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-22 19:51:20 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-22 19:54:31 +0200 |
commit | 702a75a8c0355737e3e62735b59fe30bee7e42f4 (patch) | |
tree | 538b2acd579eabf893fd1f63bc7093b65b620f28 /config/config.go | |
parent | 232f7fe1be917bf91f6342946f6d001948b8559e (diff) |
Save history to disk. Fixes #1
Diffstat (limited to 'config/config.go')
-rw-r--r-- | config/config.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/config/config.go b/config/config.go index 7d99274..5c1d87c 100644 --- a/config/config.go +++ b/config/config.go @@ -30,19 +30,29 @@ type Config struct { UserID string `yaml:"mxid"` HS string `yaml:"homeserver"` - dir string `yaml:"-"` - Session *Session `yaml:"-"` + Dir string `yaml:"-"` + HistoryDir string `yaml:"history_dir"` + Session *Session `yaml:"-"` } func NewConfig(dir string) *Config { return &Config{ - dir: dir, + Dir: dir, + HistoryDir: filepath.Join(dir, "history"), } } +func (config *Config) Clear() { + if config.Session != nil { + config.Session.Clear() + } + os.RemoveAll(config.HistoryDir) +} + func (config *Config) Load() { - os.MkdirAll(config.dir, 0700) - configPath := filepath.Join(config.dir, "config.yaml") + os.MkdirAll(config.Dir, 0700) + os.MkdirAll(config.HistoryDir, 0700) + configPath := filepath.Join(config.Dir, "config.yaml") data, err := ioutil.ReadFile(configPath) if err != nil { if os.IsNotExist(err) { @@ -61,14 +71,14 @@ func (config *Config) Load() { } func (config *Config) Save() { - os.MkdirAll(config.dir, 0700) + os.MkdirAll(config.Dir, 0700) data, err := yaml.Marshal(&config) if err != nil { debug.Print("Failed to marshal config") panic(err) } - path := filepath.Join(config.dir, "config.yaml") + path := filepath.Join(config.Dir, "config.yaml") err = ioutil.WriteFile(path, data, 0600) if err != nil { debug.Print("Failed to write config to", path) |