Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Jan 9, 2025
1 parent 536b709 commit 6c1a74d
Showing 1 changed file with 31 additions and 3 deletions.
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

0 comments on commit 6c1a74d

Please sign in to comment.