diff --git a/app/src/main/java/foundation/e/drive/fileFilters/AppSettingsFileFilter.java b/app/src/main/java/foundation/e/drive/fileFilters/AppSettingsFileFilter.java
deleted file mode 100644
index 956efe440c761f356c461467991fb43ffc20990c..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/fileFilters/AppSettingsFileFilter.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright © CLEUS SAS 2018-2019.
- * Copyright © ECORP SAS 2020.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v3.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/gpl.html
- */
-
-package foundation.e.drive.fileFilters;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.Locale;
-
-/**
- * @author Vincent Bourgmayer
- * FileFilter for application Settings
- */
-class AppSettingsFileFilter implements FileFilter {
- @Override
- public boolean accept(File pathname) {
- return pathname.isFile()
- || (pathname.isDirectory()
- && !pathname.getName().toLowerCase(Locale.ROOT).contains("cache"));
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/fileFilters/CrashlogsFileFilter.java b/app/src/main/java/foundation/e/drive/fileFilters/CrashlogsFileFilter.java
deleted file mode 100644
index 6f28fddc676678d23811123d12a6ec5d26875f82..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/fileFilters/CrashlogsFileFilter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright © CLEUS SAS 2018-2019.
- * Copyright © ECORP SAS 2020.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v3.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/gpl.html
- */
-
-package foundation.e.drive.fileFilters;
-
-import androidx.annotation.NonNull;
-
-import java.io.File;
-import java.io.FileFilter;
-
-import foundation.e.drive.utils.ServiceExceptionHandler;
-
-/**
- * @Author Vincent Bourgmayer
- */
-public class CrashlogsFileFilter implements FileFilter {
- private final static long max_timestamp_delta = 864000000; //10 days in ms (240*3600*1000)
-
- @Override
- public boolean accept(@NonNull File pathname) {
- String fileTimestamp = extractTimestamp(pathname.getName(),
- ServiceExceptionHandler.LOG_FILE_NAME_PREFIX,
- ServiceExceptionHandler.LOG_FILE_EXTENSION);
-
- long timestamp;
- try {
- timestamp = Long.parseLong(fileTimestamp);
- }catch (NumberFormatException e){
- //Can't parse the extracted timestamp
- //This file has not the expected name. It must be removed
- return true;
- }
-
- //if current Date - file date >= max deta allowed
- return ((System.currentTimeMillis() - timestamp ) >= max_timestamp_delta);
- }
-
- /**
- * Extract the timestamp from the name of the file
- * UnitTested!
- * @param fileName Filename
- * @param prefix prefix to ignore
- * @param extension extension to ignore
- * @return the timestamp extracted from the name
- */
- private String extractTimestamp(String fileName, @NonNull String prefix, @NonNull String extension){
- return fileName.substring(prefix.length(), (fileName.length() - extension.length()));
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.java b/app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.java
deleted file mode 100644
index f015396523da9e6119345778fdab92d2a7cf50e2..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright © CLEUS SAS 2018-2019.
- * Copyright © ECORP SAS 2020.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v3.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/gpl.html
- */
-
-package foundation.e.drive.fileFilters;
-
-import androidx.annotation.NonNull;
-
-import java.io.FileFilter;
-
-/**
- * @author Vincent Bourgmayer
- */
-public class FileFilterFactory {
-
- @NonNull
- public static FileFilter getFileFilter(@NonNull String category){
- FileFilter filter;
- switch (category){
- case "Rom settings":
- filter = new SettingsFileFilter();
- break;
- case "Applications":
- filter = new AppSettingsFileFilter();
- break;
- case "media":
- filter = new MediaFileFilter();
- break;
- default:
- filter = new NoCacheFileFilter();
- break;
- }
- return filter;
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.kt b/app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.kt
new file mode 100644
index 0000000000000000000000000000000000000000..cf7fd21e46ff91d3c5dc35ebb283be7e9e904156
--- /dev/null
+++ b/app/src/main/java/foundation/e/drive/fileFilters/FileFilterFactory.kt
@@ -0,0 +1,73 @@
+/*
+ * Copyright MURENA SAS 2024
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package foundation.e.drive.fileFilters;
+
+import foundation.e.drive.utils.AppConstants
+import foundation.e.drive.utils.FileUtils
+import java.io.File
+import java.io.FileFilter
+
+/**
+ * @author Vincent Bourgmayer
+ * @author Fahim Salam Chowdhury
+ */
+object FileFilterFactory {
+
+ fun buildFileFilter(category: String?): FileFilter {
+ return when (category) {
+ "Rom settings" -> buildSettingsFilter()
+ "Applications" -> buildAppSettingsFilter()
+ "media" -> BasicFileFilter()
+ else -> buildNoCacheFileFilter()
+ }
+ }
+
+ private fun buildSettingsFilter(): FileFilter {
+ return object : BasicFileFilter() {
+ override fun accept(pathname: File?): Boolean {
+ return super.accept(pathname) && pathname!!.isFile &&
+ (pathname.name.startsWith("settings_") && pathname.name.endsWith(".xml")
+ || pathname.name == AppConstants.APPLICATIONS_LIST_FILE_NAME)
+ }
+ }
+ }
+
+ private fun buildAppSettingsFilter(): FileFilter {
+ return object : BasicFileFilter() {
+ override fun accept(pathname: File?): Boolean {
+ return (super.accept(pathname)
+ && (pathname!!.isFile || (pathname.isDirectory
+ && !pathname.name.lowercase().contains("cache"))))
+ }
+ }
+ }
+
+ private fun buildNoCacheFileFilter(): FileFilter {
+ return object : BasicFileFilter() {
+ override fun accept(pathname: File?): Boolean {
+ return super.accept(pathname) &&
+ !pathname!!.name.lowercase().contains("cache")
+ }
+ }
+ }
+}
+
+private open class BasicFileFilter : FileFilter {
+ override fun accept(pathname: File?): Boolean {
+ return pathname != null && !pathname.isHidden && FileUtils.isNotPartFile(pathname)
+ }
+}
diff --git a/app/src/main/java/foundation/e/drive/fileFilters/MediaFileFilter.java b/app/src/main/java/foundation/e/drive/fileFilters/MediaFileFilter.java
deleted file mode 100644
index 6ac1740a766dc308978117983e2bfb8da96dd8cb..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/fileFilters/MediaFileFilter.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright © CLEUS SAS 2018-2019.
- * Copyright © ECORP SAS 2020.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v3.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/gpl.html
- */
-
-package foundation.e.drive.fileFilters;
-
-import java.io.File;
-import java.io.FileFilter;
-
-/**
- * @author Vincent Bourgmayer
- */
-class MediaFileFilter implements FileFilter {
- /**
- * Only accept not hidden files:
- * Media should not be synced if they're hidden files
- * @param file File to check
- * @return true if file is accepted
- */
- @Override
- public boolean accept(File file) {
- return !file.isHidden();
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/fileFilters/NoCacheFileFilter.java b/app/src/main/java/foundation/e/drive/fileFilters/NoCacheFileFilter.java
deleted file mode 100644
index 075f7d92562e9451a9e42982dfd16986e58ec4ab..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/fileFilters/NoCacheFileFilter.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright © CLEUS SAS 2018-2019.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v3.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/gpl.html
- */
-package foundation.e.drive.fileFilters;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.util.Locale;
-
-/**
- * @author Vincent Bourgmayer
- */
-class NoCacheFileFilter implements FileFilter {
- @Override
- public boolean accept(File pathname) {
- return ( ! pathname.getName().toLowerCase(Locale.ROOT).contains("cache") );
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/fileFilters/OnlyFileFilter.java b/app/src/main/java/foundation/e/drive/fileFilters/OnlyFileFilter.java
deleted file mode 100644
index a5b4b32dedeebcc9d15c22c4e4da059dfac54d99..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/fileFilters/OnlyFileFilter.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright © CLEUS SAS 2018-2019.
- * Copyright © ECORP SAS 2020.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v3.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/gpl.html
- */
-
-package foundation.e.drive.fileFilters;
-
-import androidx.annotation.NonNull;
-
-import java.io.File;
-import java.io.FileFilter;
-
-/**
- * @author Vincent Bourgmayer
- */
-public class OnlyFileFilter implements FileFilter {
- @Override
- public boolean accept(@NonNull File pathname) {
- return (!pathname.isDirectory());
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/fileFilters/SettingsFileFilter.java b/app/src/main/java/foundation/e/drive/fileFilters/SettingsFileFilter.java
deleted file mode 100644
index 6c1420796c0580a4ba2909421c8954d054f5ce46..0000000000000000000000000000000000000000
--- a/app/src/main/java/foundation/e/drive/fileFilters/SettingsFileFilter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright © CLEUS SAS 2018-2019.
- * Copyright © ECORP SAS 2020.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the GNU Public License v3.0
- * which accompanies this distribution, and is available at
- * http://www.gnu.org/licenses/gpl.html
- */
-
-package foundation.e.drive.fileFilters;
-
-import java.io.File;
-import java.io.FileFilter;
-import foundation.e.drive.utils.AppConstants;
-
-/**
- * @author Vincent Bourgmayer
- * @author Narinder Rana
- * Filter for Device settings synchronisation
- */
- class SettingsFileFilter implements FileFilter {
- /**
- * Only accept file with name beginning by "settings_" and ending with ".xml".
- * @param pathName path to analyze
- * @return True if accepted or false
- */
- @Override
- public boolean accept(File pathName) {
- String name = pathName.getName();
- return ( pathName.isFile() &&
- ( ( name.startsWith("settings_") && name.endsWith(".xml") )
- || name.equals( AppConstants.APPLICATIONS_LIST_FILE_NAME ) ) );
- }
-}
diff --git a/app/src/main/java/foundation/e/drive/fileObservers/FileEventHandler.kt b/app/src/main/java/foundation/e/drive/fileObservers/FileEventHandler.kt
index e93ea972574861380c14fd5e753f410e7a7c975e..480fc48b62ae12d80e44c3f4685b8462aee290ac 100644
--- a/app/src/main/java/foundation/e/drive/fileObservers/FileEventHandler.kt
+++ b/app/src/main/java/foundation/e/drive/fileObservers/FileEventHandler.kt
@@ -20,6 +20,7 @@ import foundation.e.drive.models.SyncRequest
import foundation.e.drive.models.SyncedFileState
import foundation.e.drive.models.SyncedFolder
import foundation.e.drive.synchronization.SyncProxy
+import foundation.e.drive.utils.FileUtils
import foundation.e.drive.utils.FileUtils.getLocalPath
import timber.log.Timber
import java.io.File
@@ -32,6 +33,10 @@ import java.io.File
class FileEventHandler(private val context: Context) {
fun onEvent(event: Int, file: File) {
+ if (FileUtils.isPartFile(file)) {
+ return
+ }
+
if (file.isDirectory) {
handleDirectoryEvent(event, file)
return
diff --git a/app/src/main/java/foundation/e/drive/fileObservers/FileObserverManager.kt b/app/src/main/java/foundation/e/drive/fileObservers/FileObserverManager.kt
index 39bb91fa1f22afda9336b5ea084159e3fdf15d22..5a7e687042fd5add6b592e808ba910176d27fb80 100644
--- a/app/src/main/java/foundation/e/drive/fileObservers/FileObserverManager.kt
+++ b/app/src/main/java/foundation/e/drive/fileObservers/FileObserverManager.kt
@@ -14,6 +14,7 @@ import android.os.Build
import android.os.FileObserver
import foundation.e.drive.database.DbHelper
import foundation.e.drive.models.SyncedFolder
+import foundation.e.drive.utils.FileUtils
import timber.log.Timber
import java.io.File
import java.io.FileFilter
@@ -28,7 +29,7 @@ class FileObserverManager(private val context: Context) : FileEventListener {
companion object {
val WATCHABLE_DIRECTORIES_FILTER = FileFilter {
- it.isDirectory && !it.isHidden
+ it.isDirectory && !it.isHidden && FileUtils.isNotPartFile(it)
}
}
diff --git a/app/src/main/java/foundation/e/drive/periodicScan/contentScanner/LocalFileLister.java b/app/src/main/java/foundation/e/drive/periodicScan/contentScanner/LocalFileLister.java
index 11d2c58d891490445fbf7b8caf58c80caad28899..43bc066206043522bb0ed9bd862b3c06d169772e 100644
--- a/app/src/main/java/foundation/e/drive/periodicScan/contentScanner/LocalFileLister.java
+++ b/app/src/main/java/foundation/e/drive/periodicScan/contentScanner/LocalFileLister.java
@@ -105,7 +105,7 @@ public class LocalFileLister extends AbstractFileLister {
folder = new FolderWrapper(dir);
final String category = syncedFolder.isMediaType() ? "media" : syncedFolder.getLibelle();
- final FileFilter filter = FileFilterFactory.getFileFilter(category);
+ final FileFilter filter = FileFilterFactory.INSTANCE.buildFileFilter(category);
final File[] files = dir.listFiles(filter);
if (files != null) {
folder.addContent(Arrays.asList(files));
diff --git a/app/src/main/java/foundation/e/drive/utils/FileUtils.kt b/app/src/main/java/foundation/e/drive/utils/FileUtils.kt
index 77185ebdc069cb47c985c1ea22c6883b43e92aa3..2a7c87eeb09da59355285e21f1f77632452239cf 100644
--- a/app/src/main/java/foundation/e/drive/utils/FileUtils.kt
+++ b/app/src/main/java/foundation/e/drive/utils/FileUtils.kt
@@ -66,4 +66,10 @@ object FileUtils {
return "*/*"
}
}
+
+ @JvmStatic
+ fun isPartFile(file: File) = file.name.endsWith(".part")
+
+ @JvmStatic
+ fun isNotPartFile(file: File) = !isPartFile(file)
}
\ No newline at end of file