GODT-1916: Use XDG_DATA_HOME to store persistent data on linux

This change ensures persistent data is stored in XDG_DATA_HOME
instead of XDG_CACHE_HOME on linux.

It adds the UserData() method on locations.Provider to return a path
suitable for storing persistent data. On linux, this returns
$XDG_DATA_HOME/protonmail (likely ~/.local/share/protonmail), and on
non-linux this returns os.UserConfigDir() because that is assumed
to be a more persistent location than os.UserCacheDir().

locations.Locations has been modified to use this new data directory;
gluon and logs are now stored here.
This commit is contained in:
James Houlahan
2022-10-28 10:50:13 +02:00
parent a553ced979
commit 2fbecc4675
4 changed files with 78 additions and 11 deletions

View File

@ -27,13 +27,17 @@ import (
)
type fakeAppDirs struct {
configDir, cacheDir string
configDir, dataDir, cacheDir string
}
func (dirs *fakeAppDirs) UserConfig() string {
return dirs.configDir
}
func (dirs *fakeAppDirs) UserData() string {
return dirs.dataDir
}
func (dirs *fakeAppDirs) UserCache() string {
return dirs.cacheDir
}
@ -134,6 +138,7 @@ func TestRemoveOldGoIMAPCacheFolders(t *testing.T) {
func newFakeAppDirs(t *testing.T) *fakeAppDirs {
return &fakeAppDirs{
configDir: t.TempDir(),
dataDir: t.TempDir(),
cacheDir: t.TempDir(),
}
}