From ad9f646102caf2079c6939fabdef7ccf292c0e52 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 2 Aug 2020 11:52:37 -0400 Subject: [PATCH] Fix downloads not working for custom SD card paths (closes #3564) --- .../java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt index f07774b08..7600aaedc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt @@ -34,11 +34,14 @@ object DiskUtil { * Gets the available space for the disk that a file path points to, in bytes. */ fun getAvailableStorageSpace(f: UniFile): Long { - val stat = StatFs(f.filePath) - val availBlocks = stat.availableBlocksLong - val blockSize = stat.blockSizeLong + val stat = try { + StatFs(f.filePath) + } catch (_: Exception) { + // Assume that exception is thrown when path is on external storage + StatFs(Environment.getExternalStorageDirectory().path) + } - return availBlocks * blockSize + return stat.availableBlocksLong * stat.blockSizeLong } /**