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 @@ -14,7 +14,6 @@ import android.provider.MediaStore
import com.nextcloud.client.database.dao.FileSystemDao
import com.nextcloud.client.database.entity.FilesystemEntity
import com.nextcloud.utils.extensions.shouldSkipFile
import com.nextcloud.utils.extensions.toFile
import com.owncloud.android.datamodel.SyncedFolder
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.lib.common.utils.Log_OC
Expand Down Expand Up @@ -60,27 +59,19 @@ class FileSystemRepository(
val entities = dao.getAutoUploadFilesEntities(syncedFolderId, BATCH_SIZE, lastId)
val filtered = mutableListOf<Pair<String, Int>>()

entities.forEach { entity ->
entity.localPath?.let { path ->
val file = File(path)
if (!file.exists()) {
Log_OC.w(TAG, "Ignoring file for upload (doesn't exist): $path")
deleteAutoUploadAndUploadEntity(syncedFolder, path, entity)
} else if (!SyncedFolderUtils.isQualifiedFolder(file.parent)) {
Log_OC.w(TAG, "Ignoring file for upload (unqualified folder): $path")
deleteAutoUploadAndUploadEntity(syncedFolder, path, entity)
} else if (!SyncedFolderUtils.isFileNameQualifiedForAutoUpload(file.name)) {
Log_OC.w(TAG, "Ignoring file for upload (unqualified file): $path")
deleteAutoUploadAndUploadEntity(syncedFolder, path, entity)
} else {
Log_OC.d(TAG, "Adding path to upload: $path")
for (entity in entities) {
val file = SyncedFolderUtils.validateForAutoUpload(entity.localPath)
if (file == null) {
deleteAutoUploadAndUploadEntity(syncedFolder, entity.localPath ?: "", entity)
continue
}

if (entity.id != null) {
filtered.add(path to entity.id)
} else {
Log_OC.w(TAG, "cant adding path to upload, id is null")
}
}
Log_OC.d(TAG, "Adding path to upload: ${entity.localPath}")

if (entity.id != null) {
filtered.add(entity.localPath!! to entity.id)
} else {
Log_OC.w(TAG, "cant adding path to upload, id is null")
}
}

Expand Down Expand Up @@ -176,7 +167,7 @@ class FileSystemRepository(
checkFileType: Boolean = false
) {
try {
val file = localPath?.toFile()
val file = SyncedFolderUtils.validateForAutoUpload(localPath)
if (file == null) {
Log_OC.w(TAG, "file null, cannot insert or replace: $localPath")
return
Expand All @@ -187,7 +178,7 @@ class FileSystemRepository(
return
}

val entity = dao.getFileByPathAndFolder(localPath, syncedFolder.id.toString())
val entity = dao.getFileByPathAndFolder(localPath!!, syncedFolder.id.toString())

val fileModified = (lastModified ?: file.lastModified())
val hasNotChanged = entity?.fileModified == fileModified
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/com/owncloud/android/utils/SyncedFolderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
*/
package com.owncloud.android.utils

import com.nextcloud.utils.extensions.toFile
import com.owncloud.android.datamodel.MediaFolder
import com.owncloud.android.datamodel.MediaFolderType
import com.owncloud.android.datamodel.SyncedFolder
import com.owncloud.android.lib.common.utils.Log_OC
import java.io.File

/**
* Utility class with methods for processing synced folders.
*/
object SyncedFolderUtils {
private const val TAG = "SyncedFolderUtils"

private val DISQUALIFIED_MEDIA_DETECTION_SOURCE = listOf(
"cover.jpg",
"cover.jpeg",
Expand Down Expand Up @@ -174,4 +178,25 @@ object SyncedFolderUtils {
}
return false
}

@Suppress("ReturnCount")
fun validateForAutoUpload(path: String?): File? {
val file = path?.toFile()
if (file == null) {
Log_OC.w(TAG, "Ignoring file for upload (doesn't exist): $path")
return null
}

if (!isQualifiedFolder(file.parent)) {
Log_OC.w(TAG, "Ignoring file for upload (unqualified folder): $path")
return null
}

if (!isFileNameQualifiedForAutoUpload(file.name)) {
Log_OC.w(TAG, "Ignoring file for upload (unqualified file): $path")
return null
}

return file
}
}
Loading