Update mautrix-go and move crypto store to XDG_DATA_HOME

This commit is contained in:
Tulir Asokan
2020-04-28 22:00:37 +03:00
parent 92d4279b21
commit fa04323daf
6 changed files with 79 additions and 36 deletions

View File

@ -65,6 +65,7 @@ type Config struct {
NotifySound bool `yaml:"notify_sound"`
Dir string `yaml:"-"`
DataDir string `yaml:"data_dir"`
CacheDir string `yaml:"cache_dir"`
HistoryPath string `yaml:"history_path"`
RoomListPath string `yaml:"room_list_path"`
@ -81,9 +82,10 @@ type Config struct {
}
// NewConfig creates a config that loads data from the given directory.
func NewConfig(configDir, cacheDir, downloadDir string) *Config {
func NewConfig(configDir, dataDir, cacheDir, downloadDir string) *Config {
return &Config{
Dir: configDir,
DataDir: dataDir,
CacheDir: cacheDir,
DownloadDir: downloadDir,
HistoryPath: filepath.Join(cacheDir, "history.db"),
@ -108,8 +110,14 @@ func (config *Config) Clear() {
config.nosave = true
}
// ClearData clears non-temporary session data.
func (config *Config) ClearData() {
_ = os.RemoveAll(config.DataDir)
}
func (config *Config) CreateCacheDirs() {
_ = os.MkdirAll(config.CacheDir, 0700)
_ = os.MkdirAll(config.DataDir, 0700)
_ = os.MkdirAll(config.StateDir, 0700)
_ = os.MkdirAll(config.MediaDir, 0700)
}
@ -122,6 +130,7 @@ func (config *Config) DeleteSession() {
config.Rooms = rooms.NewRoomCache(config.RoomListPath, config.StateDir, config.RoomCacheSize, config.RoomCacheAge, config.GetUserID)
config.PushRules = nil
config.ClearData()
config.Clear()
config.nosave = false
config.CreateCacheDirs()