mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 05:35:39 +03:00
ignore thumbnail-related data on auto upload
Resolves #7085 Resolves #4350 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
608dbd998f
commit
2113ea26f2
3 changed files with 60 additions and 51 deletions
|
@ -35,26 +35,27 @@ import java.util.Arrays
|
|||
class SyncedFolderUtilsTest : AbstractIT() {
|
||||
@Test
|
||||
fun assertCoverFilenameUnqualified() {
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(COVER))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("cover.JPG"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("cover.jpeg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("cover.JPEG"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("COVER.jpg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(FOLDER))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("Folder.jpeg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("FOLDER.jpg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(".thumbdata4--1967290299"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload(COVER))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("cover.JPG"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("cover.jpeg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("cover.JPEG"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("COVER.jpg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload(FOLDER))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("Folder.jpeg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("FOLDER.jpg"))
|
||||
Assert.assertFalse(SyncedFolderUtils.isFileNameQualifiedForAutoUpload(THUMBDATA_FILE))
|
||||
THUMBDATA_FILE
|
||||
}
|
||||
|
||||
@Test
|
||||
fun assertImageFilenameQualified() {
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("image.jpg"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("screenshot.JPG"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(IMAGE_JPEG))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("image.JPEG"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("SCREENSHOT.jpg"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForMediaDetection(SELFIE))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForMediaDetection("screenshot.PNG"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("image.jpg"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("screenshot.JPG"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForAutoUpload(IMAGE_JPEG))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("image.JPEG"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("SCREENSHOT.jpg"))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForAutoUpload(SELFIE))
|
||||
Assert.assertTrue(SyncedFolderUtils.isFileNameQualifiedForAutoUpload("screenshot.PNG"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -153,33 +154,9 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
|||
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun assertUnqualifiedSyncedFolder() {
|
||||
val tempPath = File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + ".thumbnail")
|
||||
if (!tempPath.exists()) {
|
||||
Assert.assertTrue(tempPath.mkdirs())
|
||||
}
|
||||
getDummyFile(".thumbnail/image.jpg")
|
||||
val folder = SyncedFolder(
|
||||
tempPath.absolutePath,
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
account.name,
|
||||
1,
|
||||
1,
|
||||
true,
|
||||
0L,
|
||||
MediaFolderType.IMAGE,
|
||||
false)
|
||||
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun assertUnqualifiedContentSyncedFolder() {
|
||||
val image = getDummyFile(THUMBDATA_FOLDER + File.pathSeparator + IMAGE_JPEG)
|
||||
getDummyFile(THUMBDATA_FOLDER + File.pathSeparator + THUMBDATA_FILE)
|
||||
val folder = SyncedFolder(
|
||||
FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + THUMBDATA_FOLDER,
|
||||
"",
|
||||
|
@ -193,7 +170,30 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
|||
true,
|
||||
0L,
|
||||
MediaFolderType.IMAGE,
|
||||
false)
|
||||
false
|
||||
)
|
||||
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun assertUnqualifiedSyncedFolder() {
|
||||
getDummyFile(THUMBNAILS_FOLDER + File.pathSeparator + IMAGE_JPEG)
|
||||
getDummyFile(THUMBNAILS_FOLDER + File.pathSeparator + IMAGE_BITMAP)
|
||||
val folder = SyncedFolder(
|
||||
FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + THUMBNAILS_FOLDER,
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
account.name,
|
||||
1,
|
||||
1,
|
||||
true,
|
||||
0L,
|
||||
MediaFolderType.IMAGE,
|
||||
false
|
||||
)
|
||||
Assert.assertFalse(SyncedFolderUtils.isQualifyingMediaFolder(folder))
|
||||
}
|
||||
|
||||
|
@ -207,13 +207,14 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
|||
private const val SONG_TWO = "song2.mp3"
|
||||
private const val FOLDER = "folder.JPG"
|
||||
private const val COVER = "cover.jpg"
|
||||
private const val THUMBDATA_FOLDER = "thumbdata_test";
|
||||
private const val THUMBDATA_FILE = "thumbdata_test";
|
||||
private const val THUMBNAILS_FOLDER = ".thumbnails"
|
||||
private const val THUMBDATA_FOLDER = "valid_folder"
|
||||
private const val THUMBDATA_FILE = ".thumbdata4--1967290299"
|
||||
private const val ITERATION = 100
|
||||
|
||||
@BeforeClass
|
||||
fun setUp() {
|
||||
val tempPath = File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + THUMBDATA_FOLDER)
|
||||
val tempPath = File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + THUMBNAILS_FOLDER)
|
||||
if (!tempPath.exists()) {
|
||||
tempPath.mkdirs()
|
||||
}
|
||||
|
@ -229,6 +230,8 @@ class SyncedFolderUtilsTest : AbstractIT() {
|
|||
createFile(COVER, ITERATION)
|
||||
|
||||
createFile(THUMBDATA_FOLDER + File.pathSeparator + THUMBDATA_FILE, ITERATION)
|
||||
createFile(THUMBNAILS_FOLDER + File.pathSeparator + IMAGE_JPEG, ITERATION)
|
||||
createFile(THUMBNAILS_FOLDER + File.pathSeparator + IMAGE_BITMAP, ITERATION)
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.net.Uri;
|
|||
|
||||
import com.owncloud.android.db.ProviderMeta;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.utils.SyncedFolderUtils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
|
@ -96,8 +97,13 @@ public class FilesystemDataProvider {
|
|||
if (value == null) {
|
||||
Log_OC.e(TAG, "Cannot get local path");
|
||||
} else {
|
||||
if (".thumbnail".equals(new File(value).getName())) {
|
||||
Log_OC.d(TAG, "Ignoring file for upload: " + value);
|
||||
File file = new File(value);
|
||||
if (!file.exists()) {
|
||||
Log_OC.d(TAG, "Ignoring file for upload (doesn't exist): " + value);
|
||||
} else if (SyncedFolderUtils.isQualifiedFolder(file.getParent())) {
|
||||
Log_OC.d(TAG, "Ignoring file for upload (unqualified folder): " + value);
|
||||
} else if (SyncedFolderUtils.isFileNameQualifiedForAutoUpload(file.getName())) {
|
||||
Log_OC.d(TAG, "Ignoring file for upload (unqualified file): " + value);
|
||||
} else {
|
||||
localPathsToUpload.add(value);
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ public final class SyncedFolderUtils {
|
|||
* @param folderPath the folder's path string
|
||||
* @return code>true</code> if folder qualifies for auto upload else <code>false</code>
|
||||
*/
|
||||
private static boolean isQualifiedFolder(String folderPath) {
|
||||
public static boolean isQualifiedFolder(String folderPath) {
|
||||
File folder = new File(folderPath);
|
||||
// check if folder starts with thumbnail praefix
|
||||
return !folder.isDirectory() || folder.getName() == null || !folder.getName().startsWith(THUMBNAIL_FOLDER_PREFIX);
|
||||
|
@ -180,7 +180,7 @@ public final class SyncedFolderUtils {
|
|||
*/
|
||||
private static boolean containsQualifiedImages(List<String> filePaths) {
|
||||
for (String filePath : filePaths) {
|
||||
if (isFileNameQualifiedForMediaDetection(FileUtil.getFilenameFromPathString(filePath))
|
||||
if (isFileNameQualifiedForAutoUpload(FileUtil.getFilenameFromPathString(filePath))
|
||||
&& MimeTypeUtil.isImage(MimeTypeUtil.getMimeTypeFromPath(filePath))) {
|
||||
return true;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ public final class SyncedFolderUtils {
|
|||
*/
|
||||
private static boolean containsQualifiedImages(File... files) {
|
||||
for (File file : files) {
|
||||
if (isFileNameQualifiedForMediaDetection(file.getName()) && MimeTypeUtil.isImage(file)) {
|
||||
if (isFileNameQualifiedForAutoUpload(file.getName()) && MimeTypeUtil.isImage(file)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ public final class SyncedFolderUtils {
|
|||
* @param fileName file name to be checked
|
||||
* @return <code>true</code> if the file qualifies as auto upload relevant else <code>false</code>
|
||||
*/
|
||||
public static boolean isFileNameQualifiedForMediaDetection(String fileName) {
|
||||
public static boolean isFileNameQualifiedForAutoUpload(String fileName) {
|
||||
if (fileName != null) {
|
||||
return !DISQUALIFIED_MEDIA_DETECTION_FILE_SET.contains(fileName.toLowerCase(Locale.ROOT))
|
||||
&& !fileName.startsWith(THUMBNAIL_DATA_FILE_PREFIX);
|
||||
|
|
Loading…
Reference in a new issue