diff --git a/internal/app/vault.go b/internal/app/vault.go index fe58c25d..d49be879 100644 --- a/internal/app/vault.go +++ b/internal/app/vault.go @@ -89,12 +89,12 @@ func newVault(locations *locations.Locations) (*vault.Vault, bool, bool, error) vaultKey = key } - gluonDir, err := locations.ProvideGluonPath() + gluonCacheDir, err := locations.ProvideGluonCachePath() if err != nil { return nil, false, false, fmt.Errorf("could not provide gluon path: %w", err) } - vault, corrupt, err := vault.New(vaultDir, gluonDir, vaultKey) + vault, corrupt, err := vault.New(vaultDir, gluonCacheDir, vaultKey) if err != nil { return nil, false, false, fmt.Errorf("could not create vault: %w", err) } diff --git a/internal/bridge/bridge.go b/internal/bridge/bridge.go index 2073e4e4..396e68f1 100644 --- a/internal/bridge/bridge.go +++ b/internal/bridge/bridge.go @@ -216,19 +216,19 @@ func newBridge( return nil, fmt.Errorf("failed to load TLS config: %w", err) } - gluonDir, err := getGluonDir(vault) + gluonCacheDir, err := getGluonDir(vault) if err != nil { return nil, fmt.Errorf("failed to get Gluon directory: %w", err) } - gluonDBDir, err := locator.ProvideGluonPath() + gluonConfigDir, err := locator.ProvideGluonConfigPath() if err != nil { return nil, fmt.Errorf("failed to get Gluon Database directory: %w", err) } imapServer, err := newIMAPServer( - gluonDir, - gluonDBDir, + gluonCacheDir, + gluonConfigDir, curVersion, tlsConfig, reporter, diff --git a/internal/bridge/bridge_test.go b/internal/bridge/bridge_test.go index 79be477c..1958957e 100644 --- a/internal/bridge/bridge_test.go +++ b/internal/bridge/bridge_test.go @@ -490,7 +490,7 @@ func TestBridge_InitGluonDirectory(t *testing.T) { _, err = os.ReadDir(bridge.ApplyGluonCachePathSuffix(b.GetGluonCacheDir())) require.False(t, os.IsNotExist(err)) - _, err = os.ReadDir(bridge.ApplyGluonDBPathSuffix(configDir)) + _, err = os.ReadDir(bridge.ApplyGluonConfigPathSuffix(configDir)) require.False(t, os.IsNotExist(err)) }) }) @@ -533,7 +533,7 @@ func TestBridge_ChangeCacheDirectory(t *testing.T) { _, err = os.ReadDir(bridge.ApplyGluonCachePathSuffix(currentCacheDir)) require.True(t, os.IsNotExist(err)) // Database should not have changed. - _, err = os.ReadDir(bridge.ApplyGluonDBPathSuffix(configDir)) + _, err = os.ReadDir(bridge.ApplyGluonConfigPathSuffix(configDir)) require.False(t, os.IsNotExist(err)) // New path should have Gluon sub-folder. diff --git a/internal/bridge/imap.go b/internal/bridge/imap.go index 9922bbfa..8380cfe0 100644 --- a/internal/bridge/imap.go +++ b/internal/bridge/imap.go @@ -225,13 +225,13 @@ func ApplyGluonCachePathSuffix(basePath string) string { return filepath.Join(basePath, "backend", "store") } -func ApplyGluonDBPathSuffix(basePath string) string { +func ApplyGluonConfigPathSuffix(basePath string) string { return filepath.Join(basePath, "backend", "db") } // nolint:funlen func newIMAPServer( - gluonCacheDir, gluonDBDir string, + gluonCacheDir, gluonConfigDir string, version *semver.Version, tlsConfig *tls.Config, reporter reporter.Reporter, @@ -240,11 +240,11 @@ func newIMAPServer( tasks *async.Group, ) (*gluon.Server, error) { gluonCacheDir = ApplyGluonCachePathSuffix(gluonCacheDir) - gluonDBDir = ApplyGluonDBPathSuffix(gluonDBDir) + gluonConfigDir = ApplyGluonConfigPathSuffix(gluonConfigDir) logrus.WithFields(logrus.Fields{ "gluonStore": gluonCacheDir, - "gluonDB": gluonDBDir, + "gluonDB": gluonConfigDir, "version": version, "logClient": logClient, "logServer": logServer, @@ -276,7 +276,7 @@ func newIMAPServer( imapServer, err := gluon.New( gluon.WithTLS(tlsConfig), gluon.WithDataDir(gluonCacheDir), - gluon.WithDatabaseDir(gluonDBDir), + gluon.WithDatabaseDir(gluonConfigDir), gluon.WithStoreBuilder(new(storeBuilder)), gluon.WithLogger(imapClientLog, imapServerLog), getGluonVersionInfo(version), diff --git a/internal/bridge/settings.go b/internal/bridge/settings.go index a0771ffe..dd274636 100644 --- a/internal/bridge/settings.go +++ b/internal/bridge/settings.go @@ -120,7 +120,7 @@ func (bridge *Bridge) GetGluonCacheDir() string { } func (bridge *Bridge) GetGluonConfigDir() (string, error) { - return bridge.locator.ProvideGluonPath() + return bridge.locator.ProvideGluonConfigPath() } func (bridge *Bridge) SetGluonDir(ctx context.Context, newGluonDir string) error { @@ -353,10 +353,10 @@ func (bridge *Bridge) FactoryReset(ctx context.Context) { }, bridge.usersLock) // Wipe the vault. - gluonDir, err := bridge.locator.ProvideGluonPath() + gluonCacheDir, err := bridge.locator.ProvideGluonCachePath() if err != nil { logrus.WithError(err).Error("Failed to provide gluon dir") - } else if err := bridge.vault.Reset(gluonDir); err != nil { + } else if err := bridge.vault.Reset(gluonCacheDir); err != nil { logrus.WithError(err).Error("Failed to reset vault") } diff --git a/internal/bridge/types.go b/internal/bridge/types.go index c42bae81..2250fd38 100644 --- a/internal/bridge/types.go +++ b/internal/bridge/types.go @@ -26,7 +26,8 @@ import ( type Locator interface { ProvideSettingsPath() (string, error) ProvideLogsPath() (string, error) - ProvideGluonPath() (string, error) + ProvideGluonCachePath() (string, error) + ProvideGluonConfigPath() (string, error) GetLicenseFilePath() string GetDependencyLicensesLink() string Clear() error diff --git a/internal/locations/locations.go b/internal/locations/locations.go index 44c09627..781deee8 100644 --- a/internal/locations/locations.go +++ b/internal/locations/locations.go @@ -138,14 +138,24 @@ func (l *Locations) ProvideSettingsPath() (string, error) { return l.getSettingsPath(), nil } -// ProvideGluonPath returns a location for gluon data. +// ProvideGluonConfigPath returns a location for gluon data. // It creates it if it doesn't already exist. -func (l *Locations) ProvideGluonPath() (string, error) { - if err := os.MkdirAll(l.getGluonPath(), 0o700); err != nil { +func (l *Locations) ProvideGluonConfigPath() (string, error) { + if err := os.MkdirAll(l.getGluonConfigPath(), 0o700); err != nil { return "", err } - return l.getGluonPath(), nil + return l.getGluonConfigPath(), nil +} + +// ProvideGluonCachePath returns a location for gluon message cache data (does not need to be persistent). +// It creates it if it doesn't already exist. +func (l *Locations) ProvideGluonCachePath() (string, error) { + if err := os.MkdirAll(l.getGluonCachePath(), 0o700); err != nil { + return "", err + } + + return l.getGluonCachePath(), nil } // ProvideLogsPath returns a location for user logs (e.g. ~/.local/share///logs). @@ -178,7 +188,11 @@ func (l *Locations) ProvideUpdatesPath() (string, error) { return l.getUpdatesPath(), nil } -func (l *Locations) getGluonPath() string { +func (l *Locations) getGluonCachePath() string { + return filepath.Join(l.userCache, "gluon") +} + +func (l *Locations) getGluonConfigPath() string { return filepath.Join(l.userData, "gluon") } @@ -231,7 +245,7 @@ func (l *Locations) Clean() error { l.GetGuiLockFile(), l.getLogsPath(), l.getUpdatesPath(), - l.getGluonPath(), + l.getGluonConfigPath(), ).Do() } diff --git a/internal/vault/vault.go b/internal/vault/vault.go index 11f7c426..d37b5389 100644 --- a/internal/vault/vault.go +++ b/internal/vault/vault.go @@ -47,7 +47,7 @@ type Vault struct { } // New constructs a new encrypted data vault at the given filepath using the given encryption key. -func New(vaultDir, gluonDir string, key []byte) (*Vault, bool, error) { +func New(vaultDir, gluonCacheDir string, key []byte) (*Vault, bool, error) { if err := os.MkdirAll(vaultDir, 0o700); err != nil { return nil, false, err } @@ -64,7 +64,7 @@ func New(vaultDir, gluonDir string, key []byte) (*Vault, bool, error) { return nil, false, err } - vault, corrupt, err := newVault(filepath.Join(vaultDir, "vault.enc"), gluonDir, gcm) + vault, corrupt, err := newVault(filepath.Join(vaultDir, "vault.enc"), gluonCacheDir, gcm) if err != nil { return nil, false, err } diff --git a/tests/bridge_test.go b/tests/bridge_test.go index 8338eaa6..da3df3c8 100644 --- a/tests/bridge_test.go +++ b/tests/bridge_test.go @@ -88,12 +88,19 @@ func (s *scenario) theUserChangesTheGluonPath() error { } func (s *scenario) theUserDeletesTheGluonFiles() error { - path, err := s.t.locator.ProvideGluonPath() - if err != nil { - return err + if path, err := s.t.locator.ProvideGluonCachePath(); err != nil { + return fmt.Errorf("failed to get gluon cache path: %w", err) + } else if err := os.RemoveAll(path); err != nil { + return fmt.Errorf("failed to remove gluon cache path: %w", err) } - return os.RemoveAll(path) + if path, err := s.t.locator.ProvideGluonConfigPath(); err != nil { + return fmt.Errorf("failed to get gluon config path: %w", err) + } else if err := os.RemoveAll(path); err != nil { + return fmt.Errorf("failed to remove gluon config path: %w", err) + } + + return nil } func (s *scenario) theUserHasDisabledAutomaticUpdates() error { diff --git a/tests/ctx_bridge_test.go b/tests/ctx_bridge_test.go index 531ca864..8f89cc4b 100644 --- a/tests/ctx_bridge_test.go +++ b/tests/ctx_bridge_test.go @@ -100,13 +100,13 @@ func (t *testCtx) initBridge() (<-chan events.Event, error) { } // Get the default gluon path. - gluonDir, err := t.locator.ProvideGluonPath() + gluonCacheDir, err := t.locator.ProvideGluonCachePath() if err != nil { return nil, fmt.Errorf("could not get gluon dir: %w", err) } // Create the vault. - vault, corrupt, err := vault.New(vaultDir, gluonDir, t.storeKey) + vault, corrupt, err := vault.New(vaultDir, gluonCacheDir, t.storeKey) if err != nil { return nil, fmt.Errorf("could not create vault: %w", err) } else if corrupt {