mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 20:56:51 +00:00
Other: Don't clean settings path on teardown
This commit is contained in:
@ -322,14 +322,7 @@ func WithLocations(fn func(*locations.Locations) error) error {
|
||||
}
|
||||
|
||||
// Create a new locations object that will be used to provide paths to store files.
|
||||
locations := locations.New(provider, constants.ConfigName)
|
||||
defer func() {
|
||||
if err := locations.Clean(); err != nil {
|
||||
logrus.WithError(err).Error("Failed to clean locations")
|
||||
}
|
||||
}()
|
||||
|
||||
return fn(locations)
|
||||
return fn(locations.New(provider, constants.ConfigName))
|
||||
}
|
||||
|
||||
// Start profiling if requested.
|
||||
|
||||
@ -235,20 +235,6 @@ func (l *Locations) ClearUpdates() error {
|
||||
).Do()
|
||||
}
|
||||
|
||||
// Clean removes any unexpected files from the app cache folder
|
||||
// while leaving files in the standard locations untouched.
|
||||
func (l *Locations) Clean() error {
|
||||
return files.Remove(
|
||||
l.userCache,
|
||||
l.userData,
|
||||
).Except(
|
||||
l.GetGuiLockFile(),
|
||||
l.getLogsPath(),
|
||||
l.getUpdatesPath(),
|
||||
l.getGluonConfigPath(),
|
||||
).Do()
|
||||
}
|
||||
|
||||
// CleanGoIMAPCache removes all cache data from the go-imap implementation.
|
||||
func (l *Locations) CleanGoIMAPCache() error {
|
||||
return files.Remove(l.getGoIMAPCachePath()).Do()
|
||||
|
||||
@ -63,54 +63,6 @@ func TestClearUpdateFiles(t *testing.T) {
|
||||
assert.NoDirExists(t, l.getUpdatesPath())
|
||||
}
|
||||
|
||||
func TestCleanLeavesStandardLocationsUntouched(t *testing.T) {
|
||||
l := newTestLocations(t)
|
||||
|
||||
createFilesInDir(t, l.getLogsPath(),
|
||||
"log1.txt",
|
||||
"log2.txt",
|
||||
)
|
||||
|
||||
assert.NoError(t, l.Clean())
|
||||
|
||||
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.getUpdatesPath())
|
||||
}
|
||||
|
||||
func TestCleanRemovesUnexpectedFilesAndFolders(t *testing.T) {
|
||||
l := newTestLocations(t)
|
||||
|
||||
createFilesInDir(t, l.userCache,
|
||||
"unexpected1.txt",
|
||||
"dir1/unexpected2.txt",
|
||||
"dir1/unexpected3.txt",
|
||||
"dir2/unexpected4.txt",
|
||||
"dir3/dir4/unexpected5.txt",
|
||||
)
|
||||
|
||||
require.FileExists(t, filepath.Join(l.userCache, "unexpected1.txt"))
|
||||
require.FileExists(t, filepath.Join(l.userCache, "dir1", "unexpected2.txt"))
|
||||
require.FileExists(t, filepath.Join(l.userCache, "dir1", "unexpected3.txt"))
|
||||
require.FileExists(t, filepath.Join(l.userCache, "dir2", "unexpected4.txt"))
|
||||
require.FileExists(t, filepath.Join(l.userCache, "dir3", "dir4", "unexpected5.txt"))
|
||||
|
||||
assert.NoError(t, l.Clean())
|
||||
|
||||
assert.DirExists(t, l.getSettingsPath())
|
||||
assert.DirExists(t, l.getLogsPath())
|
||||
assert.DirExists(t, l.getUpdatesPath())
|
||||
|
||||
assert.NoFileExists(t, filepath.Join(l.userCache, "unexpected1.txt"))
|
||||
assert.NoFileExists(t, filepath.Join(l.userCache, "dir1", "unexpected2.txt"))
|
||||
assert.NoFileExists(t, filepath.Join(l.userCache, "dir1", "unexpected3.txt"))
|
||||
assert.NoFileExists(t, filepath.Join(l.userCache, "dir2", "unexpected4.txt"))
|
||||
assert.NoFileExists(t, filepath.Join(l.userCache, "dir3", "dir4", "unexpected5.txt"))
|
||||
}
|
||||
|
||||
func TestRemoveOldGoIMAPCacheFolders(t *testing.T) {
|
||||
l := newTestLocations(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user