mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 20:31:02 -05:00
Swallow errors when trying to determine available disk space when downloading (closes #3603)
This commit is contained in:
parent
421dfb4a2d
commit
3e6b0117fd
2 changed files with 7 additions and 8 deletions
|
@ -267,15 +267,16 @@ class Downloader(
|
||||||
* @param download the chapter to be downloaded.
|
* @param download the chapter to be downloaded.
|
||||||
*/
|
*/
|
||||||
private fun downloadChapter(download: Download): Observable<Download> = Observable.defer {
|
private fun downloadChapter(download: Download): Observable<Download> = Observable.defer {
|
||||||
val chapterDirname = provider.getChapterDirName(download.chapter)
|
|
||||||
val mangaDir = provider.getMangaDir(download.manga, download.source)
|
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
|
download.status = Download.ERROR
|
||||||
notifier.onError(context.getString(R.string.download_insufficient_space), download.chapter.name)
|
notifier.onError(context.getString(R.string.download_insufficient_space), download.chapter.name)
|
||||||
return@defer Observable.just(download)
|
return@defer Observable.just(download)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val chapterDirname = provider.getChapterDirName(download.chapter)
|
||||||
val tmpDir = mangaDir.createDirectory(chapterDirname + TMP_DIR_SUFFIX)
|
val tmpDir = mangaDir.createDirectory(chapterDirname + TMP_DIR_SUFFIX)
|
||||||
|
|
||||||
val pageListObservable = if (download.pages == null) {
|
val pageListObservable = if (download.pages == null) {
|
||||||
|
|
|
@ -34,14 +34,12 @@ object DiskUtil {
|
||||||
* Gets the available space for the disk that a file path points to, in bytes.
|
* Gets the available space for the disk that a file path points to, in bytes.
|
||||||
*/
|
*/
|
||||||
fun getAvailableStorageSpace(f: UniFile): Long {
|
fun getAvailableStorageSpace(f: UniFile): Long {
|
||||||
val stat = try {
|
return try {
|
||||||
StatFs(f.filePath)
|
val stat = StatFs(f.uri.path)
|
||||||
|
stat.availableBlocksLong * stat.blockSizeLong
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
// Assume that exception is thrown when path is on external storage
|
-1L
|
||||||
StatFs(Environment.getExternalStorageDirectory().path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stat.availableBlocksLong * stat.blockSizeLong
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue