Skip to content

Commit 9ac0390

Browse files
alperozturk96backportbot[bot]
authored andcommitted
cover edge cases
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 9b649e8 commit 9ac0390

7 files changed

Lines changed: 63 additions & 15 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/autoUpload/AutoUploadWorker.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.nextcloud.client.jobs.upload.FileUploadWorker
2424
import com.nextcloud.client.jobs.utils.UploadErrorNotificationManager
2525
import com.nextcloud.client.network.ConnectivityService
2626
import com.nextcloud.utils.extensions.isNonRetryable
27+
import com.nextcloud.utils.extensions.updateStatus
2728
import com.owncloud.android.R
2829
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
2930
import com.owncloud.android.datamodel.FileDataStorageManager
@@ -341,6 +342,10 @@ class AutoUploadWorker(
341342
sendUploadFinishEvent(operation, result)
342343
}
343344
} catch (e: Exception) {
345+
uploadsStorageManager.updateStatus(
346+
uploadEntity,
347+
UploadsStorageManager.UploadStatus.UPLOAD_FAILED
348+
)
344349
Log_OC.e(
345350
TAG,
346351
"Exception during upload file, localPath: $localPath, remotePath: $remotePath," +

app/src/main/java/com/nextcloud/client/jobs/autoUpload/FileSystemRepository.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,6 @@ class FileSystemRepository(
183183
val entity = dao.getFileByPathAndFolder(localPath, syncedFolder.id.toString())
184184

185185
val fileModified = (lastModified ?: file.lastModified())
186-
if (fileModified <= 0L) {
187-
Log_OC.d(TAG, "file is deleted, skipping: $localPath")
188-
entity?.let {
189-
deleteAutoUploadAndUploadEntity(syncedFolder, localPath, entity)
190-
}
191-
return
192-
}
193-
194186
val hasNotChanged = entity?.fileModified == fileModified
195187
val fileSentForUpload = entity?.fileSentForUpload == 1
196188

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.nextcloud.client.network.ConnectivityService
2424
import com.nextcloud.client.preferences.AppPreferences
2525
import com.nextcloud.utils.ForegroundServiceHelper
2626
import com.nextcloud.utils.extensions.getPercent
27+
import com.nextcloud.utils.extensions.updateStatus
2728
import com.owncloud.android.R
2829
import com.owncloud.android.datamodel.FileDataStorageManager
2930
import com.owncloud.android.datamodel.ForegroundServiceType
@@ -255,7 +256,7 @@ class FileUploadWorker(
255256
)
256257

257258
val result = withContext(Dispatchers.IO) {
258-
upload(operation, user, client)
259+
upload(upload, operation, user, client)
259260
}
260261
currentUploadFileOperation = null
261262

@@ -327,6 +328,7 @@ class FileUploadWorker(
327328

328329
@Suppress("TooGenericExceptionCaught", "DEPRECATION")
329330
private suspend fun upload(
331+
upload: OCUpload,
330332
operation: UploadFileOperation,
331333
user: User,
332334
client: OwnCloudClient
@@ -343,6 +345,14 @@ class FileUploadWorker(
343345
fileUploadBroadcastManager.sendStarted(operation, context)
344346
} catch (e: Exception) {
345347
Log_OC.e(TAG, "Error uploading", e)
348+
uploadsStorageManager.run {
349+
uploadDao.getUploadById(upload.uploadId, user.accountName)?.let { entity ->
350+
updateStatus(
351+
entity,
352+
UploadsStorageManager.UploadStatus.UPLOAD_FAILED
353+
)
354+
}
355+
}
346356
result = RemoteOperationResult(e)
347357
} finally {
348358
if (!isStopped) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.nextcloud.utils.extensions
9+
10+
import com.nextcloud.client.database.entity.UploadEntity
11+
import com.owncloud.android.datamodel.UploadsStorageManager
12+
13+
fun UploadsStorageManager.updateStatus(entity: UploadEntity?, status: UploadsStorageManager.UploadStatus) {
14+
entity ?: return
15+
uploadDao.insertOrReplace(entity.withStatus(status))
16+
}
17+
18+
fun UploadsStorageManager.updateStatus(entity: UploadEntity?, success: Boolean) {
19+
entity ?: return
20+
val newStatus = if (success) {
21+
UploadsStorageManager.UploadStatus.UPLOAD_SUCCEEDED
22+
} else {
23+
UploadsStorageManager.UploadStatus.UPLOAD_FAILED
24+
}
25+
uploadDao.insertOrReplace(entity.withStatus(newStatus))
26+
}
27+
28+
private fun UploadEntity.withStatus(newStatus: UploadsStorageManager.UploadStatus) = this.copy(status = newStatus.value)

app/src/main/java/com/owncloud/android/MainApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public void disableDocumentsStorageProvider() {
392392
FilesSyncHelper.startAutoUploadForEnabledSyncedFolders(syncedFolderProvider,
393393
backgroundJobManager,
394394
new String[]{},
395-
true);
395+
false);
396396
preferences.setLastAutoUploadOnStartTime(System.currentTimeMillis());
397397
}
398398
} else if (event == Lifecycle.Event.ON_STOP) {

app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ public void updateDatabaseUploadResult(RemoteOperationResult uploadResult, Uploa
582582
result = UploadResult.SYNC_CONFLICT;
583583
}
584584
} else if (code == RemoteOperationResult.ResultCode.LOCAL_FILE_NOT_FOUND) {
585+
// upload status is SUCCEEDED because user cannot take action about it, it will always fail
586+
status = UploadStatus.UPLOAD_SUCCEEDED;
585587
result = UploadResult.FILE_NOT_FOUND;
586588
}
587589

app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,10 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
11061106
throw new OperationCancelledException();
11071107
}
11081108

1109-
// Execute
1110-
result = mUploadOperation.execute(client);
1109+
// execute
1110+
if (result.isSuccess() && mUploadOperation != null) {
1111+
result = mUploadOperation.execute(client);
1112+
}
11111113

11121114
// move local temporal file or original file to its corresponding
11131115
// location in the Nextcloud local folder
@@ -1129,11 +1131,20 @@ private RemoteOperationResult normalUpload(OwnCloudClient client) {
11291131
} finally {
11301132
mUploadStarted.set(false);
11311133

1132-
// Clean up temporal file if it exists
1133-
if (temporalFile != null && !temporalFile.delete() && temporalFile.exists()) {
1134-
Log_OC.e(TAG, "Could not delete temporal file");
1134+
// clean up temporal file if it exists
1135+
try {
1136+
if (temporalFile != null) {
1137+
if (temporalFile.exists() && !temporalFile.delete()) {
1138+
Log_OC.e(TAG, "Could not delete temporal file");
1139+
}
1140+
} else {
1141+
Log_OC.e(TAG, "temporal file is null, cannot delete it");
1142+
}
1143+
} catch (Exception e) {
1144+
Log_OC.e(TAG, "an exception occurred during deletion of temporal file: ", e);
11351145
}
11361146

1147+
11371148
if (result == null) {
11381149
result = new RemoteOperationResult<>(ResultCode.UNKNOWN_ERROR);
11391150
}

0 commit comments

Comments
 (0)