GODT-1779: Remove go-imap

This commit is contained in:
James Houlahan
2022-08-26 17:00:21 +02:00
parent 3b0bc1ca15
commit 39433fe707
593 changed files with 12725 additions and 91626 deletions

View File

@ -51,11 +51,6 @@ func New(provider Provider, configName string) *Locations {
}
}
// GetLockFile returns the path to the lock file (e.g. ~/.cache/<company>/<app>/<app>.lock).
func (l *Locations) GetLockFile() string {
return filepath.Join(l.userCache, l.configName+".lock")
}
// GetGuiLockFile returns the path to the lock file (e.g. ~/.cache/<company>/<app>/<app>.lock).
func (l *Locations) GetGuiLockFile() string {
return filepath.Join(l.userCache, l.configGuiName+".lock")
@ -127,6 +122,16 @@ func (l *Locations) ProvideSettingsPath() (string, error) {
return l.getSettingsPath(), nil
}
// ProvideGluonPath 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 {
return "", err
}
return l.getGluonPath(), nil
}
// ProvideLogsPath returns a location for user logs (e.g. ~/.cache/<company>/<app>/logs).
// It creates it if it doesn't already exist.
func (l *Locations) ProvideLogsPath() (string, error) {
@ -137,19 +142,14 @@ func (l *Locations) ProvideLogsPath() (string, error) {
return l.getLogsPath(), nil
}
// ProvideCachePath returns a location for user cache dirs (e.g. ~/.config/<company>/<app>/cache).
// ProvideGUICertPath returns a location for TLS certs used for the connection between bridge and the GUI.
// It creates it if it doesn't already exist.
func (l *Locations) ProvideCachePath() (string, error) {
if err := os.MkdirAll(l.getCachePath(), 0o700); err != nil {
func (l *Locations) ProvideGUICertPath() (string, error) {
if err := os.MkdirAll(l.getGUICertPath(), 0o700); err != nil {
return "", err
}
return l.getCachePath(), nil
}
// GetOldCachePath returns a former location for user cache dirs used for migration scripts only.
func (l *Locations) GetOldCachePath() string {
return filepath.Join(l.userCache, "cache")
return l.getGUICertPath(), nil
}
// ProvideUpdatesPath returns a location for update files (e.g. ~/.cache/<company>/<app>/updates).
@ -172,6 +172,14 @@ func (l *Locations) GetOldUpdatesPath() string {
return filepath.Join(l.userCache, "updates")
}
func (l *Locations) getGluonPath() string {
return filepath.Join(l.userCache, "gluon")
}
func (l *Locations) getGUICertPath() string {
return l.userConfig
}
func (l *Locations) getSettingsPath() string {
return l.userConfig
}
@ -180,22 +188,6 @@ func (l *Locations) getLogsPath() string {
return filepath.Join(l.userCache, "logs")
}
func (l *Locations) getCachePath() string {
// Bridge cache is not a typical cache which can be deleted with only
// downside that the app has to download everything again.
// Cache for bridge is database with IMAP UIDs and UIDVALIDITY, and also
// other IMAP setup. Deleting such data leads to either re-sync of client,
// or mix of headers and bodies. Both is caused because of need of re-sync
// between Bridge and API which will happen in different order than before.
// In the first case, UIDVALIDITY is also changed and causes the better
// outcome to "just" re-sync everything; in the later, UIDVALIDITY stays
// the same, causing the client to not re-sync but UIDs in the client does
// not match UIDs in Bridge.
// Because users might use tools to regularly clear caches, Bridge cache
// cannot be located in a standard cache folder.
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
@ -216,7 +208,6 @@ func (l *Locations) Clear() error {
l.userConfig,
l.userCache,
).Except(
l.GetLockFile(),
l.GetGuiLockFile(),
l.getUpdatesPath(),
).Do()
@ -233,10 +224,8 @@ func (l *Locations) ClearUpdates() error {
// while leaving files in the standard locations untouched.
func (l *Locations) Clean() error {
return files.Remove(l.userCache).Except(
l.GetLockFile(),
l.GetGuiLockFile(),
l.getLogsPath(),
l.getCachePath(),
l.getUpdatesPath(),
).Do()
}

View File

@ -43,11 +43,9 @@ func TestClearRemovesEverythingExceptLockAndUpdateFiles(t *testing.T) {
assert.NoError(t, l.Clear())
assert.FileExists(t, l.GetLockFile())
assert.DirExists(t, l.getSettingsPath())
assert.NoFileExists(t, filepath.Join(l.getSettingsPath(), "prefs.json"))
assert.NoDirExists(t, l.getLogsPath())
assert.NoDirExists(t, l.getCachePath())
assert.DirExists(t, l.getUpdatesPath())
}
@ -56,11 +54,9 @@ func TestClearUpdateFiles(t *testing.T) {
assert.NoError(t, l.ClearUpdates())
assert.FileExists(t, l.GetLockFile())
assert.DirExists(t, l.getSettingsPath())
assert.FileExists(t, filepath.Join(l.getSettingsPath(), "prefs.json"))
assert.DirExists(t, l.getLogsPath())
assert.DirExists(t, l.getCachePath())
assert.NoDirExists(t, l.getUpdatesPath())
}
@ -74,13 +70,11 @@ func TestCleanLeavesStandardLocationsUntouched(t *testing.T) {
assert.NoError(t, l.Clean())
assert.FileExists(t, l.GetLockFile())
assert.DirExists(t, l.getSettingsPath())
assert.FileExists(t, filepath.Join(l.getSettingsPath(), "prefs.json"))
assert.DirExists(t, l.getLogsPath())
assert.FileExists(t, filepath.Join(l.getLogsPath(), "log1.txt"))
assert.FileExists(t, filepath.Join(l.getLogsPath(), "log2.txt"))
assert.DirExists(t, l.getCachePath())
assert.DirExists(t, l.getUpdatesPath())
}
@ -103,10 +97,8 @@ func TestCleanRemovesUnexpectedFilesAndFolders(t *testing.T) {
assert.NoError(t, l.Clean())
assert.FileExists(t, l.GetLockFile())
assert.DirExists(t, l.getSettingsPath())
assert.DirExists(t, l.getLogsPath())
assert.DirExists(t, l.getCachePath())
assert.DirExists(t, l.getUpdatesPath())
assert.NoFileExists(t, filepath.Join(l.userCache, "unexpected1.txt"))
@ -117,25 +109,15 @@ func TestCleanRemovesUnexpectedFilesAndFolders(t *testing.T) {
}
func newFakeAppDirs(t *testing.T) *fakeAppDirs {
configDir, err := os.MkdirTemp("", "test-locations-config")
require.NoError(t, err)
cacheDir, err := os.MkdirTemp("", "test-locations-cache")
require.NoError(t, err)
return &fakeAppDirs{
configDir: configDir,
cacheDir: cacheDir,
configDir: t.TempDir(),
cacheDir: t.TempDir(),
}
}
func newTestLocations(t *testing.T) *Locations {
l := New(newFakeAppDirs(t), "configName")
lock := l.GetLockFile()
createFilesInDir(t, "", lock)
require.FileExists(t, lock)
settings, err := l.ProvideSettingsPath()
require.NoError(t, err)
require.DirExists(t, settings)
@ -147,10 +129,6 @@ func newTestLocations(t *testing.T) *Locations {
require.NoError(t, err)
require.DirExists(t, logs)
cache, err := l.ProvideCachePath()
require.NoError(t, err)
require.DirExists(t, cache)
updates, err := l.ProvideUpdatesPath()
require.NoError(t, err)
require.DirExists(t, updates)