Skip to content

Commit

Permalink
Merge pull request #807 from Adamantcheese/(#770)-add-even-more-logs
Browse files Browse the repository at this point in the history
(#770) Add even more logs to figure out the reason of cache handler exception when trying to create the dirs
  • Loading branch information
Adamantcheese authored Mar 7, 2020
2 parents f72f332 + ccde268 commit 5bde49d
Showing 1 changed file with 23 additions and 10 deletions.
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

0 comments on commit 5bde49d

Please sign in to comment.