diff --git a/app/src/androidTest/java/com/owncloud/android/utils/SyncedFolderUtilsTest.kt b/app/src/androidTest/java/com/owncloud/android/utils/SyncedFolderUtilsTest.kt index 1093ae015985..310affdba943 100644 --- a/app/src/androidTest/java/com/owncloud/android/utils/SyncedFolderUtilsTest.kt +++ b/app/src/androidTest/java/com/owncloud/android/utils/SyncedFolderUtilsTest.kt @@ -11,6 +11,7 @@ import com.owncloud.android.AbstractIT import com.owncloud.android.datamodel.MediaFolder import com.owncloud.android.datamodel.MediaFolderType import com.owncloud.android.datamodel.SyncedFolder +import com.owncloud.android.utils.SyncedFolderUtils.hasExcludePrefix import org.apache.commons.io.FileUtils import org.junit.AfterClass import org.junit.Assert @@ -205,6 +206,21 @@ class SyncedFolderUtilsTest : AbstractIT() { Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder)) } + @Test + fun testInstantUploadPathIgnoreExcludedPrefixes() { + val testFiles = listOf( + "IMG_nnn.jpg", + "my_documents", + "Music", + ".trashed_IMG_nnn.jpg", + ".pending_IMG_nnn.jpg", + ".nomedia", + ".thumbdata_IMG_nnn", + ".thumbnail" + ).filter { !hasExcludePrefix(it) } + Assert.assertTrue(testFiles.size == 3) + } + companion object { private const val SELFIE = "selfie.png" private const val SCREENSHOT = "screenshot.JPG" diff --git a/app/src/main/java/com/owncloud/android/utils/SyncedFolderUtils.kt b/app/src/main/java/com/owncloud/android/utils/SyncedFolderUtils.kt index e627f9f109b0..285e6be88a8c 100644 --- a/app/src/main/java/com/owncloud/android/utils/SyncedFolderUtils.kt +++ b/app/src/main/java/com/owncloud/android/utils/SyncedFolderUtils.kt @@ -24,9 +24,14 @@ object SyncedFolderUtils { ) private val DISQUALIFIED_MEDIA_DETECTION_FILE_SET: Set = DISQUALIFIED_MEDIA_DETECTION_SOURCE.toSet() private val AUTO_QUALIFYING_FOLDER_TYPE_SET: Set = setOf(MediaFolderType.CUSTOM) - private const val THUMBNAIL_FOLDER_PREFIX = ".thumbnail" - private const val THUMBNAIL_DATA_FILE_PREFIX = ".thumbdata" private const val SINGLE_FILE = 1 + private val EXCLUDE_PREFIXES = listOf( + ".thumbnail", + ".thumbdata", + ".trashed", + ".pending", + ".nomedia" + ) /** * analyzes a given media folder if its content qualifies for the folder to be handled as a media folder. @@ -105,7 +110,7 @@ object SyncedFolderUtils { } val folder = File(folderPath) // check if folder starts with thumbnail prefix - return folder.isDirectory && !folder.name.startsWith(THUMBNAIL_FOLDER_PREFIX) + return folder.isDirectory && !hasExcludePrefix(folder.name) } /** @@ -129,7 +134,7 @@ object SyncedFolderUtils { return when { fileName != null -> { !DISQUALIFIED_MEDIA_DETECTION_FILE_SET.contains(fileName.lowercase()) && - !fileName.startsWith(THUMBNAIL_DATA_FILE_PREFIX) + !hasExcludePrefix(fileName) } else -> false } @@ -148,4 +153,21 @@ object SyncedFolderUtils { .sortedBy { it.second } .map { it.first } } + + /** + * check if file or folder name has prefix in the list to exclude from auto upload + * + * @param name name of file to check + * @return `true` if file has one of the prefixes in EXCLUDE_FILENAME_PREFIXES + */ + fun hasExcludePrefix(name: String?): Boolean { + if (name != null) { + EXCLUDE_PREFIXES.forEach { + if (name.startsWith(it)) { + return true + } + } + } + return false + } }