mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 15:46:44 +00:00
GODT-1813: Cleanup old go-imap cache files
This commit is contained in:
committed by
James Houlahan
parent
e0ff30e9a8
commit
d47b5b99c5
@ -41,6 +41,9 @@ import (
|
|||||||
|
|
||||||
const vaultSecretName = "bridge-vault-key"
|
const vaultSecretName = "bridge-vault-key"
|
||||||
|
|
||||||
|
// deleteOldGoIMAPFiles Set with `-ldflags -X app.deleteOldGoIMAPFiles=true` to enable cleanup of old imap cache data.
|
||||||
|
var deleteOldGoIMAPFiles bool //nolint:gochecknoglobals
|
||||||
|
|
||||||
// withBridge creates creates and tears down the bridge.
|
// withBridge creates creates and tears down the bridge.
|
||||||
func withBridge( //nolint:funlen
|
func withBridge( //nolint:funlen
|
||||||
c *cli.Context,
|
c *cli.Context,
|
||||||
@ -61,6 +64,13 @@ func withBridge( //nolint:funlen
|
|||||||
dialer.NewTLSPinChecker(dialer.TrustedAPIPins),
|
dialer.NewTLSPinChecker(dialer.TrustedAPIPins),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Delete old go-imap cache files
|
||||||
|
if deleteOldGoIMAPFiles {
|
||||||
|
if err := locations.CleanGoIMAPCache(); err != nil {
|
||||||
|
logrus.WithError(err).Error("Failed to remove old go-imap cache")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create a proxy dialer which switches to a proxy if the request fails.
|
// Create a proxy dialer which switches to a proxy if the request fails.
|
||||||
proxyDialer := dialer.NewProxyTLSDialer(pinningDialer, constants.APIHost)
|
proxyDialer := dialer.NewProxyTLSDialer(pinningDialer, constants.APIHost)
|
||||||
|
|
||||||
|
|||||||
@ -193,6 +193,10 @@ func (l *Locations) getLogsPath() string {
|
|||||||
return filepath.Join(l.userCache, "logs")
|
return filepath.Join(l.userCache, "logs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Locations) getGoIMAPCachePath() string {
|
||||||
|
return filepath.Join(l.userConfig, "cache")
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Locations) getUpdatesPath() string {
|
func (l *Locations) getUpdatesPath() string {
|
||||||
// In order to properly update Bridge 1.6.X and higher we need to
|
// In order to properly update Bridge 1.6.X and higher we need to
|
||||||
// change the launcher first. Since this is not part of automatic
|
// change the launcher first. Since this is not part of automatic
|
||||||
@ -235,3 +239,8 @@ func (l *Locations) Clean() error {
|
|||||||
l.getGluonPath(),
|
l.getGluonPath(),
|
||||||
).Do()
|
).Do()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CleanGoIMAPCache removes all cache data from the go-imap implementation.
|
||||||
|
func (l *Locations) CleanGoIMAPCache() error {
|
||||||
|
return files.Remove(l.getGoIMAPCachePath()).Do()
|
||||||
|
}
|
||||||
|
|||||||
@ -108,6 +108,29 @@ func TestCleanRemovesUnexpectedFilesAndFolders(t *testing.T) {
|
|||||||
assert.NoFileExists(t, filepath.Join(l.userCache, "dir3", "dir4", "unexpected5.txt"))
|
assert.NoFileExists(t, filepath.Join(l.userCache, "dir3", "dir4", "unexpected5.txt"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRemoveOldGoIMAPCacheFolders(t *testing.T) {
|
||||||
|
l := newTestLocations(t)
|
||||||
|
|
||||||
|
createFilesInDir(t,
|
||||||
|
l.getGoIMAPCachePath(),
|
||||||
|
"foo",
|
||||||
|
"bar",
|
||||||
|
)
|
||||||
|
|
||||||
|
require.FileExists(t, filepath.Join(l.getGoIMAPCachePath(), "foo"))
|
||||||
|
require.FileExists(t, filepath.Join(l.getGoIMAPCachePath(), "bar"))
|
||||||
|
|
||||||
|
assert.NoError(t, l.CleanGoIMAPCache())
|
||||||
|
|
||||||
|
assert.DirExists(t, l.getSettingsPath())
|
||||||
|
assert.DirExists(t, l.getLogsPath())
|
||||||
|
assert.DirExists(t, l.getUpdatesPath())
|
||||||
|
|
||||||
|
assert.NoFileExists(t, filepath.Join(l.getGoIMAPCachePath(), "foo"))
|
||||||
|
assert.NoFileExists(t, filepath.Join(l.getGoIMAPCachePath(), "bar"))
|
||||||
|
assert.NoDirExists(t, l.getGoIMAPCachePath())
|
||||||
|
}
|
||||||
|
|
||||||
func newFakeAppDirs(t *testing.T) *fakeAppDirs {
|
func newFakeAppDirs(t *testing.T) *fakeAppDirs {
|
||||||
return &fakeAppDirs{
|
return &fakeAppDirs{
|
||||||
configDir: t.TempDir(),
|
configDir: t.TempDir(),
|
||||||
|
|||||||
Reference in New Issue
Block a user