|
@@ -15,12 +15,13 @@ import com.nextcloud.client.device.PowerManagementService
|
|
|
import com.nextcloud.client.network.ConnectivityService
|
|
|
import com.owncloud.android.MainApp
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager
|
|
|
+import com.owncloud.android.datamodel.OCFile
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC
|
|
|
import com.owncloud.android.operations.SynchronizeFolderOperation
|
|
|
import com.owncloud.android.utils.FileStorageUtils
|
|
|
import java.io.File
|
|
|
|
|
|
-@Suppress("Detekt.NestedBlockDepth")
|
|
|
+@Suppress("Detekt.NestedBlockDepth", "ReturnCount")
|
|
|
class InternalTwoWaySyncWork(
|
|
|
private val context: Context,
|
|
|
params: WorkerParameters,
|
|
@@ -47,13 +48,8 @@ class InternalTwoWaySyncWork(
|
|
|
val folders = fileDataStorageManager.getInternalTwoWaySyncFolders(user)
|
|
|
|
|
|
for (folder in folders) {
|
|
|
- val freeSpaceLeft = File(folder.storagePath).getFreeSpace()
|
|
|
- val localFolderSize = FileStorageUtils.getFolderSize(File(folder.storagePath, MainApp.getDataFolder()))
|
|
|
- val remoteFolderSize = folder.fileLength
|
|
|
-
|
|
|
- if (freeSpaceLeft < (remoteFolderSize - localFolderSize)) {
|
|
|
- Log_OC.d(TAG, "Not enough space left!")
|
|
|
- result = false
|
|
|
+ checkFreeSpace(folder)?.let { checkFreeSpaceResult ->
|
|
|
+ return checkFreeSpaceResult
|
|
|
}
|
|
|
|
|
|
Log_OC.d(TAG, "Folder ${folder.remotePath}: started!")
|
|
@@ -85,6 +81,31 @@ class InternalTwoWaySyncWork(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Suppress("TooGenericExceptionCaught")
|
|
|
+ private fun checkFreeSpace(folder: OCFile): Result? {
|
|
|
+ val storagePath = folder.storagePath ?: MainApp.getStoragePath()
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
companion object {
|
|
|
const val TAG = "InternalTwoWaySyncWork"
|
|
|
}
|