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 1a6144a commit 51fbb8f
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 51fbb8f

Please sign in to comment.