Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#770) Add even more logs to figure out the reason of cache handler exception when trying to create the dirs #807

Merged
merged 1 commit into from
Mar 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
*/
package com.github.adamantcheese.chan.core.cache

import android.os.Environment
import android.text.TextUtils
import com.github.adamantcheese.chan.utils.BackgroundUtils
import com.github.adamantcheese.chan.utils.*
import com.github.adamantcheese.chan.utils.ConversionUtils.charArrayToInt
import com.github.adamantcheese.chan.utils.ConversionUtils.intToCharArray
import com.github.adamantcheese.chan.utils.HashingUtil
import com.github.adamantcheese.chan.utils.Logger
import com.github.adamantcheese.chan.utils.StringUtils
import com.github.k1rakishou.fsaf.FileManager
import com.github.k1rakishou.fsaf.file.AbstractFile
import com.github.k1rakishou.fsaf.file.FileDescriptorMode
Expand Down Expand Up @@ -621,25 +619,40 @@ class CacheHandler(
val rawFile = File(cacheDirFile.getFullPath())
if (!rawFile.mkdirs()) {
throw RuntimeException(
"Unable to create file cache dir ${cacheDirFile.getFullPath()}")
"Unable to create file cache dir ${cacheDirFile.getFullPath()}, " +
"additional info = ${getAdditionalDebugInfo(rawFile)}")
} else {
Logger.e(TAG, "fileManager.create failed, " +
"but rawFile.mkdirs() succeeded, cacheDirFile = ${cacheDirFile.getFullPath()}")
Logger.e(TAG, "fileManager.create failed, but rawFile.mkdirs() succeeded, " +
"cacheDirFile = ${cacheDirFile.getFullPath()}")
}
}

if (!fileManager.exists(chunksCacheDirFile) && fileManager.create(chunksCacheDirFile) == null) {
val rawFile = File(chunksCacheDirFile.getFullPath())
if (!rawFile.mkdirs()) {
throw RuntimeException(
"Unable to create file chunks cache dir ${chunksCacheDirFile.getFullPath()}")
"Unable to create file chunks cache dir ${chunksCacheDirFile.getFullPath()}, " +
"additional info = ${getAdditionalDebugInfo(rawFile)}")
} else {
Logger.e(TAG, "fileManager.create failed, " +
"but rawFile.mkdirs() succeeded, chunksCacheDirFile = ${chunksCacheDirFile.getFullPath()}")
Logger.e(TAG, "fileManager.create failed, but rawFile.mkdirs() succeeded, " +
"chunksCacheDirFile = ${chunksCacheDirFile.getFullPath()}")
}
}
}

private fun getAdditionalDebugInfo(file: File): String {
val state = Environment.getExternalStorageState(file)
val externalCacheDir = AndroidUtils.getAppContext().externalCacheDir?.absolutePath ?: "<null>"
val internalCacheDir = AndroidUtils.getAppContext().cacheDir ?: "<null>"

return "(exists = ${file.exists()}, " +
"canRead = ${file.canRead()}, " +
"canWrite = ${file.canWrite()}, " +
"state = ${state}, " +
"externalCacheDir = ${externalCacheDir}, " +
"internalCacheDir = ${internalCacheDir})"
}

private fun backgroundRecalculateSize() {
if (recalculationRunning.get()) {
// Already running. Do not use compareAndSet() here!
Expand Down