diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index 6b46e86eb8..4382333d83 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -267,15 +267,16 @@ class Downloader( * @param download the chapter to be downloaded. */ private fun downloadChapter(download: Download): Observable = Observable.defer { - val chapterDirname = provider.getChapterDirName(download.chapter) val mangaDir = provider.getMangaDir(download.manga, download.source) - if (DiskUtil.getAvailableStorageSpace(mangaDir) < MIN_DISK_SPACE) { + val availSpace = DiskUtil.getAvailableStorageSpace(mangaDir) + if (availSpace != -1L && availSpace < MIN_DISK_SPACE) { download.status = Download.ERROR notifier.onError(context.getString(R.string.download_insufficient_space), download.chapter.name) return@defer Observable.just(download) } + val chapterDirname = provider.getChapterDirName(download.chapter) val tmpDir = mangaDir.createDirectory(chapterDirname + TMP_DIR_SUFFIX) val pageListObservable = if (download.pages == null) { 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 7600aaedc0..9a2600aba2 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,14 +34,12 @@ object DiskUtil { * Gets the available space for the disk that a file path points to, in bytes. */ fun getAvailableStorageSpace(f: UniFile): Long { - val stat = try { - StatFs(f.filePath) + return try { + val stat = StatFs(f.uri.path) + stat.availableBlocksLong * stat.blockSizeLong } catch (_: Exception) { - // Assume that exception is thrown when path is on external storage - StatFs(Environment.getExternalStorageDirectory().path) + -1L } - - return stat.availableBlocksLong * stat.blockSizeLong } /**