Fix downloads not working for custom SD card paths (closes #3564)

(cherry picked from commit ad9f646102caf2079c6939fabdef7ccf292c0e52)
This commit is contained in:
arkon 2020-08-02 11:52:37 -04:00 committed by Jobobby04
parent 1f7e69e13c
commit 951bb1f3c6

View File

@ -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
}
/**