GODT-1349: Change cache-related settings when enabling/disabling/moving cache
This commit is contained in:
parent
18257f0302
commit
29af8e7178
|
@ -204,3 +204,36 @@ func (b *Bridge) GetKeychainApp() string {
|
|||
func (b *Bridge) SetKeychainApp(helper string) {
|
||||
b.settings.Set(settings.PreferredKeychainKey, helper)
|
||||
}
|
||||
|
||||
func (b *Bridge) EnableCache() error {
|
||||
// Set this back to the default location before enabling.
|
||||
b.settings.Set(settings.CacheLocationKey, "")
|
||||
|
||||
if err := b.Users.EnableCache(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.settings.SetBool(settings.CacheEnabledKey, true)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Bridge) DisableCache() error {
|
||||
if err := b.Users.DisableCache(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.settings.SetBool(settings.CacheEnabledKey, false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Bridge) MigrateCache(from, to string) error {
|
||||
if err := b.Users.MigrateCache(from, to); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.settings.Set(settings.CacheLocationKey, to)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -163,15 +163,11 @@ func (f *frontendCLI) enableCacheOnDisk(c *ishell.Context) {
|
|||
}
|
||||
|
||||
if f.yesNoQuestion("Are you sure you want to enable the local cache") {
|
||||
// Set this back to the default location before enabling.
|
||||
f.settings.Set(settings.CacheLocationKey, "")
|
||||
|
||||
if err := f.bridge.EnableCache(); err != nil {
|
||||
f.Println("The local cache could not be enabled.")
|
||||
return
|
||||
}
|
||||
|
||||
f.settings.SetBool(settings.CacheEnabledKey, true)
|
||||
f.restarter.SetToRestart()
|
||||
f.Stop()
|
||||
}
|
||||
|
@ -189,7 +185,6 @@ func (f *frontendCLI) disableCacheOnDisk(c *ishell.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
f.settings.SetBool(settings.CacheEnabledKey, false)
|
||||
f.restarter.SetToRestart()
|
||||
f.Stop()
|
||||
}
|
||||
|
@ -211,7 +206,6 @@ func (f *frontendCLI) setCacheOnDiskLocation(c *ishell.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
f.settings.Set(settings.CacheLocationKey, location)
|
||||
f.restarter.SetToRestart()
|
||||
f.Stop()
|
||||
}
|
||||
|
|
|
@ -434,6 +434,18 @@ func (u *Users) EnableCache() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (u *Users) DisableCache() error {
|
||||
// NOTE(GODT-1158): Is it an error if we can't remove a user's cache?
|
||||
|
||||
for _, user := range u.users {
|
||||
if err := user.store.RemoveCache(); err != nil {
|
||||
logrus.WithError(err).Error("Failed to remove user's message cache")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Users) MigrateCache(from, to string) error {
|
||||
// NOTE(GODT-1158): Is it enough to just close the store? Do we need to force-close the cacher too?
|
||||
|
||||
|
@ -451,18 +463,6 @@ func (u *Users) MigrateCache(from, to string) error {
|
|||
return os.Rename(from, to)
|
||||
}
|
||||
|
||||
func (u *Users) DisableCache() error {
|
||||
// NOTE(GODT-1158): Is it an error if we can't remove a user's cache?
|
||||
|
||||
for _, user := range u.users {
|
||||
if err := user.store.RemoveCache(); err != nil {
|
||||
logrus.WithError(err).Error("Failed to remove user's message cache")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// hasUser returns whether the struct currently has a user with ID `id`.
|
||||
func (u *Users) hasUser(id string) (user *User, ok bool) {
|
||||
for _, u := range u.users {
|
||||
|
|
Loading…
Reference in New Issue