From 918f30965da8cbf50a4eda384c42f48f0c2bc857 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 6 Oct 2020 10:26:37 +0300 Subject: [PATCH] EtebaseCache: fix crash when removing and re-adding (sometimes). Essentially the problem was that when we were removing the account, the cache directory was removed. Though then when readding the account, we would get the cache handler from our handler cache, which would already be init, so it'd assume the directory already exists. This was only relevant if there were network errors because otherwise the sync would also happen it the background which would create the missing dirs anyway. The solution: remove the object from the handler cache when removing account. --- .../java/com/etesync/syncadapter/EtebaseLocalCache.kt | 8 +++++++- .../java/com/etesync/syncadapter/ui/AccountActivity.kt | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/EtebaseLocalCache.kt b/app/src/main/java/com/etesync/syncadapter/EtebaseLocalCache.kt index b51c2756..5bab8e9c 100644 --- a/app/src/main/java/com/etesync/syncadapter/EtebaseLocalCache.kt +++ b/app/src/main/java/com/etesync/syncadapter/EtebaseLocalCache.kt @@ -38,7 +38,7 @@ class EtebaseLocalCache private constructor(context: Context, username: String) return File(colDir, "items") } - fun clearUserCache() { + private fun clearUserCache() { filesDir.deleteRecursively() } @@ -153,6 +153,12 @@ class EtebaseLocalCache private constructor(context: Context, username: String) } } + fun clearUserCache(context: Context, username: String) { + val localCache = getInstance(context, username) + localCache.clearUserCache() + localCacheCache.remove(username) + } + // FIXME: If we ever cache this we need to cache bust on changePassword fun getEtebase(context: Context, httpClient: OkHttpClient, settings: AccountSettings): Account { val client = Client.create(httpClient, settings.uri?.toString()) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt index 84e7938e..dbea30be 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/AccountActivity.kt @@ -562,8 +562,7 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe Logger.log.warning(e.toString()) } } else { - val etebaseLocalCache = EtebaseLocalCache.getInstance(this@AccountActivity, account.name) - etebaseLocalCache.clearUserCache() + EtebaseLocalCache.clearUserCache(this@AccountActivity, account.name) try { val httpClient = HttpClient.Builder(this@AccountActivity).build()