⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
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 @@ -36,6 +36,7 @@ import com.owncloud.android.datamodel.SyncedFolder
import com.owncloud.android.datamodel.SyncedFolderProvider
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.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.utils.Log_OC
Expand Down Expand Up @@ -320,7 +321,14 @@ class AutoUploadWorker(
)

try {
var (uploadEntity, upload) = createEntityAndUpload(user, localPath, remotePath)
val result = createEntityAndUpload(user, localPath, remotePath)
if (result == null) {
repository.markFileAsHandled(localPath, syncedFolder)
Log_OC.d(TAG, "Marked file as handled due to existing conflict: $localPath")
continue
}

var (uploadEntity, upload) = result

// if local file deleted, upload process cannot be started or retriable thus needs to be removed
if (path.isEmpty() || !file.exists()) {
Expand Down Expand Up @@ -349,7 +357,7 @@ class AutoUploadWorker(
)

if (result.isSuccess) {
repository.markFileAsUploaded(localPath, syncedFolder)
repository.markFileAsHandled(localPath, syncedFolder)
Log_OC.d(TAG, "✅ upload completed: $localPath")
} else {
Log_OC.e(
Expand Down Expand Up @@ -393,7 +401,11 @@ class AutoUploadWorker(
uploadsStorageManager.removeUpload(upload)
}

private fun createEntityAndUpload(user: User, localPath: String, remotePath: String): Pair<UploadEntity, OCUpload> {
private fun createEntityAndUpload(
user: User,
localPath: String,
remotePath: String
): Pair<UploadEntity, OCUpload>? {
Comment on lines +404 to +408
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning null in this case means that a prior upload failed due to a conflict. In my opinion we shouldn't introduce overall nullability to mean one specific thing. I would prefer if either the OCUpload becomes nullable, or if we return UploadEntity as is and check for uploadEntity?.lastResult in the calling function instead. I think that this would improve readability in the long term.

Copy link
Collaborator Author

@alperozturk96 alperozturk96 Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and...

The createEntityAndUpload function should either create both the entity and the upload together or not create them at all. We should avoid partially successful executions; it should either succeed completely or fail entirely.

One approach would be to only pass items that are eligible for mapping, ensuring the function always returns valid values.

Alternatively, we could use a sealed class or a kotlin.Result wrapper so the function would never return null.

The current approach is okay, and this logic is only used inside the worker; it is not a general function, so it’s fine to keep it as is for now. In the future, we can improve this as needed, for example, if another condition prevents mapping and we have to handle it differently in the caller function.

val (needsCharging, needsWifi, uploadAction) = getUploadSettings(syncedFolder)
Log_OC.d(TAG, "creating oc upload for ${user.accountName}")

Expand All @@ -404,6 +416,12 @@ class AutoUploadWorker(
accountName = user.accountName
)

val lastUploadResult = uploadEntity?.lastResult?.let { UploadResult.fromValue(it) }
if (lastUploadResult == UploadResult.SYNC_CONFLICT) {
Log_OC.w(TAG, "Conflict already exists, skipping auto-upload: $localPath")
return null
}

val upload = (
uploadEntity?.toOCUpload(null) ?: OCUpload(
localPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FileSystemRepository(private val dao: FileSystemDao, private val context:
return filtered
}

suspend fun markFileAsUploaded(localPath: String, syncedFolder: SyncedFolder) {
suspend fun markFileAsHandled(localPath: String, syncedFolder: SyncedFolder) {
val syncedFolderIdStr = syncedFolder.id.toString()

try {
Expand Down
Loading