Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.utils.ForegroundServiceHelper
import com.nextcloud.utils.extensions.getPercent
import com.nextcloud.utils.extensions.isNonRetryable
import com.nextcloud.utils.extensions.toFile
import com.owncloud.android.R
import com.owncloud.android.datamodel.ForegroundServiceType
Expand All @@ -34,6 +35,7 @@ import com.owncloud.android.datamodel.SyncedFolderProvider
import com.owncloud.android.datamodel.ThumbnailsCacheManager
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.OCUpload
import com.owncloud.android.db.UploadResult
import com.owncloud.android.lib.common.OwnCloudAccount
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
Expand Down Expand Up @@ -204,6 +206,18 @@ class FileUploadWorker(
.setSilent(true)
.build()

private enum class UploadFilesResult {
Success,
Error,
Retry;

fun toWorkerResult(): Result = when (this) {
Success -> Result.success()
Error -> Result.failure()
Retry -> Result.retry()
}
}

@Suppress("ReturnCount", "LongMethod", "DEPRECATION")
private suspend fun uploadFiles(): Result = withContext(Dispatchers.IO) {
val accountName = inputData.getString(ACCOUNT)
Expand Down Expand Up @@ -246,6 +260,7 @@ class FileUploadWorker(
val client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)
val syncFolderHelper = SyncFolderHelper(context)
val syncedFolders = syncedFolderProvider.syncedFolders
var uploadFilesResult = UploadFilesResult.Success

for ((index, upload) in uploads.withIndex()) {
ensureActive()
Expand Down Expand Up @@ -288,20 +303,33 @@ class FileUploadWorker(
)

val result = withContext(Dispatchers.IO) {
upload(upload, operation, user, client)
upload(operation, user, client)
}
activeOperations.remove(upload.uploadId)

// check quota first
if (result.code == ResultCode.QUOTA_EXCEEDED) {
Log_OC.w(TAG, "Quota exceeded, stopping uploads")
notificationManager.showQuotaExceedNotification(operation)
break
}

// check upload result for worker
val uploadResult = UploadResult.fromOperationResult(result)
if (!result.isSuccess) {
Log_OC.e(TAG, "upload failed for ${upload.remotePath}: ${result.code}")
if (uploadResult.isNonRetryable()) {
uploadFilesResult = UploadFilesResult.Error
} else if (uploadFilesResult != UploadFilesResult.Error) {
// only set retry if any other not failed before
uploadFilesResult = UploadFilesResult.Retry
}
}

sendUploadFinishEvent(totalUploadSize, currentUploadIndex, operation, result)
}

return@withContext Result.success()
return@withContext uploadFilesResult.toWorkerResult()
}

@Suppress("ReturnCount")
Expand Down Expand Up @@ -356,21 +384,24 @@ class FileUploadWorker(

@Suppress("TooGenericExceptionCaught", "DEPRECATION")
private suspend fun upload(
upload: OCUpload,
operation: UploadFileOperation,
user: User,
client: OwnCloudClient
): RemoteOperationResult<Any?> = withContext(Dispatchers.IO) {
lateinit var result: RemoteOperationResult<Any?>
var result: RemoteOperationResult<Any?>

try {
val storageManager = operation.storageManager
result = operation.execute(client)
val task = ThumbnailsCacheManager.ThumbnailGenerationTask(storageManager, user)
val file = File(operation.originalStoragePath)
val remoteId: String? = operation.file.remoteId
task.execute(ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, remoteId))
fileUploadEventBroadcaster.sendUploadStarted(operation, context)
result = operation.execute(client)

// only generate a thumbnail if the upload actually succeeded
if (result.isSuccess) {
val task = ThumbnailsCacheManager.ThumbnailGenerationTask(storageManager, user)
val file = File(operation.originalStoragePath)
val remoteId: String? = operation.file.remoteId
task.execute(ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, remoteId))
}
} catch (e: Exception) {
Log_OC.e(TAG, "Error uploading", e)
result = RemoteOperationResult(e)
Expand Down Expand Up @@ -405,7 +436,7 @@ class FileUploadWorker(
private var lastUpdateTime = 0L

/**
* Receives from [com.owncloud.android.operations.UploadFileOperation.normalUpload]
* Receives from [UploadFileOperation.normalUpload]
*/
@Suppress("MagicNumber")
override fun onTransferProgress(
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
androidCommonLibraryVersion = "0.33.2"
androidGifDrawableVersion = "1.2.31"
androidImageCropperVersion = "4.7.0"
androidLibraryVersion ="1f476c0ab14fb280172be2aefd70db80e50bb17b"
androidLibraryVersion ="64bab56dce"
androidOpensslVersion = "3.5.6"
androidPluginVersion = "9.2.1"
androidsvgVersion = "1.4"
Expand Down
8 changes: 8 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21345,6 +21345,14 @@
<sha256 value="12e69eebf36959a9fc9c4ae61343ec17e74f5af581accee3a14a6b8b4adacc54" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="64bab56dce">
<artifact name="android-library-64bab56dce.aar">
<sha256 value="57510727181131abcd62696b4de737b5769df4de9276dc868335f8caf65aa547" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-64bab56dce.module">
<sha256 value="9c2fa4cf6b957dd26184d88ba952fa6ae1aacdc3b959fd36c7773edd7041eda4" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="67f7bf5eb832b5fa24f06d9b84db0e21d4c8638c">
<artifact name="android-library-67f7bf5eb832b5fa24f06d9b84db0e21d4c8638c.aar">
<sha256 value="c253a126ca3c32dd5b373ab1c64668e4603305b3113b052fc0fc5e3c833a913c" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down
Loading