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

Hard-code ignore files with prefix .trashed #14384

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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 @@ -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
Expand Down Expand Up @@ -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"
Expand Down
31 changes: 27 additions & 4 deletions app/src/main/java/com/owncloud/android/utils/SyncedFolderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ object SyncedFolderUtils {
)
private val DISQUALIFIED_MEDIA_DETECTION_FILE_SET: Set<String> = DISQUALIFIED_MEDIA_DETECTION_SOURCE.toSet()
private val AUTO_QUALIFYING_FOLDER_TYPE_SET: Set<MediaFolderType> = 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.
Expand Down Expand Up @@ -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)
}

/**
Expand All @@ -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
}
Expand All @@ -148,4 +153,22 @@ 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 {
val hasPrefix = false
0ranki marked this conversation as resolved.
Show resolved Hide resolved
if (name != null) {
EXCLUDE_PREFIXES.forEach {
if (name.startsWith(it)) {
return true
}
}
}
return false
}
}