Skip to content

Commit

Permalink
catch exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <alper_ozturk@proton.me>
  • Loading branch information
alperozturk96 committed Sep 30, 2024
1 parent 67cc52b commit 160a6ca
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,29 @@ class InternalTwoWaySyncWork(
}
}

@Suppress("TooGenericExceptionCaught")
private fun checkFreeSpace(folder: OCFile): Result? {
folder.storagePath?.let { storagePath ->
val file = File(storagePath)
if (file.exists()) {
val freeSpaceLeft = file.getFreeSpace()
val localFolder = File(storagePath, MainApp.getDataFolder())
val localFolderSize = FileStorageUtils.getFolderSize(localFolder)
val remoteFolderSize = folder.fileLength

if (freeSpaceLeft < (remoteFolderSize - localFolderSize)) {
Log_OC.d(TAG, "Not enough space left!")
return Result.failure()
}
val storagePath = folder.storagePath ?: return null
val file = File(storagePath)

if (!file.exists()) return null

return try {
val freeSpaceLeft = file.freeSpace
val localFolder = File(storagePath, MainApp.getDataFolder())
val localFolderSize = FileStorageUtils.getFolderSize(localFolder)
val remoteFolderSize = folder.fileLength

if (freeSpaceLeft < (remoteFolderSize - localFolderSize)) {
Log_OC.d(TAG, "Not enough space left!")
Result.failure()
} else {
null
}
} catch (e: Exception) {
Log_OC.d(TAG, "Error caught at checkFreeSpace: $e")
null
}

return null
}

companion object {
Expand Down

0 comments on commit 160a6ca

Please sign in to comment.