Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix - Auto Upload Check File Sent For Upload #14342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 31 additions & 3 deletions app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.owncloud.android.datamodel.MediaFolderType
import com.owncloud.android.datamodel.SyncedFolder
import com.owncloud.android.datamodel.SyncedFolderProvider
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.ProviderMeta
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.activity.SettingsActivity
Expand Down Expand Up @@ -218,20 +219,47 @@ class FilesSyncWork(
syncedFolderProvider.updateSyncFolder(syncedFolder)
}

private fun getAllFiles(path: String): Set<File> {
private fun getAllFiles(path: String, syncedFolderId: String): Set<File> {
return File(path).takeIf { it.exists() }
?.walkTopDown()
?.asSequence()
?.filter { file ->
file.isFile &&
file.exists() &&
isQualifiedFolder(file.parentFile?.path) &&
isFileNameQualifiedForAutoUpload(file.name)
isFileNameQualifiedForAutoUpload(file.name) &&
!isFileUploaded(file.path, syncedFolderId)
}
?.toSet()
?: emptySet()
}

private fun isFileUploaded(path: String, syncedFolderId: String): Boolean {
val projection = arrayOf(ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD)
val selection =
"${ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH} = ? AND " +
"${ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID} = ?"
val selectionArgs = arrayOf(path, syncedFolderId)

val cursor = contentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
projection,
selection,
selectionArgs,
null
)

return cursor?.use {
if (it.moveToFirst()) {
val isSentForUpload =
it.getInt(it.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD))
isSentForUpload == 1
} else {
false
}
} ?: false
}

@Suppress("LongMethod") // legacy code
private fun uploadFilesFromFolder(
context: Context,
Expand Down Expand Up @@ -259,7 +287,7 @@ class FilesSyncWork(
null
}

val files = getAllFiles(syncedFolder.localPath)
val files = getAllFiles(syncedFolder.localPath, syncedFolder.id.toString())
if (files.isEmpty()) {
return
}
Expand Down
Loading