|
@@ -27,7 +27,7 @@ import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation
|
|
import com.owncloud.android.operations.CreateFolderOperation
|
|
import com.owncloud.android.operations.CreateFolderOperation
|
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
|
import com.owncloud.android.utils.theme.ViewThemeUtils
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.Dispatchers
|
|
-import kotlinx.coroutines.coroutineScope
|
|
|
|
|
|
+import kotlinx.coroutines.NonCancellable
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withContext
|
|
import kotlin.coroutines.resume
|
|
import kotlin.coroutines.resume
|
|
import kotlin.coroutines.suspendCoroutine
|
|
import kotlin.coroutines.suspendCoroutine
|
|
@@ -51,8 +51,7 @@ class OfflineOperationsWorker(
|
|
private var repository = OfflineOperationsRepository(fileDataStorageManager)
|
|
private var repository = OfflineOperationsRepository(fileDataStorageManager)
|
|
|
|
|
|
@Suppress("TooGenericExceptionCaught")
|
|
@Suppress("TooGenericExceptionCaught")
|
|
- override suspend fun doWork(): Result = coroutineScope {
|
|
|
|
- // fileDataStorageManager.offlineOperationDao.clearTable()
|
|
|
|
|
|
+ override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
|
|
val jobName = inputData.getString(JOB_NAME)
|
|
val jobName = inputData.getString(JOB_NAME)
|
|
Log_OC.d(
|
|
Log_OC.d(
|
|
TAG,
|
|
TAG,
|
|
@@ -63,7 +62,7 @@ class OfflineOperationsWorker(
|
|
|
|
|
|
if (!isNetworkAndServerAvailable()) {
|
|
if (!isNetworkAndServerAvailable()) {
|
|
Log_OC.d(TAG, "OfflineOperationsWorker cancelled, no internet connection")
|
|
Log_OC.d(TAG, "OfflineOperationsWorker cancelled, no internet connection")
|
|
- return@coroutineScope Result.retry()
|
|
|
|
|
|
+ return@withContext Result.retry()
|
|
}
|
|
}
|
|
|
|
|
|
val client = clientFactory.create(user)
|
|
val client = clientFactory.create(user)
|
|
@@ -73,7 +72,7 @@ class OfflineOperationsWorker(
|
|
val totalOperations = operations.size
|
|
val totalOperations = operations.size
|
|
var currentSuccessfulOperationIndex = 0
|
|
var currentSuccessfulOperationIndex = 0
|
|
|
|
|
|
- return@coroutineScope try {
|
|
|
|
|
|
+ return@withContext try {
|
|
while (operations.isNotEmpty()) {
|
|
while (operations.isNotEmpty()) {
|
|
val operation = operations.first()
|
|
val operation = operations.first()
|
|
val result = executeOperation(operation, client)
|
|
val result = executeOperation(operation, client)
|
|
@@ -113,10 +112,10 @@ class OfflineOperationsWorker(
|
|
private suspend fun executeOperation(
|
|
private suspend fun executeOperation(
|
|
operation: OfflineOperationEntity,
|
|
operation: OfflineOperationEntity,
|
|
client: OwnCloudClient
|
|
client: OwnCloudClient
|
|
- ): Pair<RemoteOperationResult<*>?, RemoteOperation<*>?>? {
|
|
|
|
- return when (operation.type) {
|
|
|
|
|
|
+ ): Pair<RemoteOperationResult<*>?, RemoteOperation<*>?>? = withContext(Dispatchers.IO) {
|
|
|
|
+ return@withContext when (operation.type) {
|
|
is OfflineOperationType.CreateFolder -> {
|
|
is OfflineOperationType.CreateFolder -> {
|
|
- val createFolderOperation = withContext(Dispatchers.IO) {
|
|
|
|
|
|
+ val createFolderOperation = withContext(NonCancellable) {
|
|
val operationType = (operation.type as OfflineOperationType.CreateFolder)
|
|
val operationType = (operation.type as OfflineOperationType.CreateFolder)
|
|
CreateFolderOperation(
|
|
CreateFolderOperation(
|
|
operationType.path,
|
|
operationType.path,
|
|
@@ -129,7 +128,7 @@ class OfflineOperationsWorker(
|
|
}
|
|
}
|
|
|
|
|
|
is OfflineOperationType.CreateFile -> {
|
|
is OfflineOperationType.CreateFile -> {
|
|
- val createFileOperation = withContext(Dispatchers.IO) {
|
|
|
|
|
|
+ val createFileOperation = withContext(NonCancellable) {
|
|
val operationType = (operation.type as OfflineOperationType.CreateFile)
|
|
val operationType = (operation.type as OfflineOperationType.CreateFile)
|
|
UploadFileRemoteOperation(
|
|
UploadFileRemoteOperation(
|
|
operationType.localPath,
|
|
operationType.localPath,
|