mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 04:36:43 +00:00
GODT-2251: Store gluon cache in user cache rather than user data
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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/<company>/<app>/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()
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user