forked from Silverfish/proton-bridge
GODT-1813: Cleanup old go-imap cache files
This commit is contained in:
committed by
James Houlahan
parent
e0ff30e9a8
commit
d47b5b99c5
@ -193,6 +193,10 @@ func (l *Locations) getLogsPath() string {
|
||||
return filepath.Join(l.userCache, "logs")
|
||||
}
|
||||
|
||||
func (l *Locations) getGoIMAPCachePath() string {
|
||||
return filepath.Join(l.userConfig, "cache")
|
||||
}
|
||||
|
||||
func (l *Locations) getUpdatesPath() string {
|
||||
// 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
|
||||
@ -235,3 +239,8 @@ func (l *Locations) Clean() error {
|
||||
l.getGluonPath(),
|
||||
).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"))
|
||||
}
|
||||
|
||||
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 {
|
||||
return &fakeAppDirs{
|
||||
configDir: t.TempDir(),
|
||||
|
||||
Reference in New Issue
Block a user