Browse Source

deleteSubDirIfParentPathMatches

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 11 months ago
parent
commit
03ea98c3e0

+ 10 - 0
app/src/main/java/com/nextcloud/utils/extensions/OfflineOperationExtensions.kt

@@ -12,6 +12,16 @@ import com.nextcloud.client.database.entity.OfflineOperationEntity
 
 private const val DELIMITER = '/'
 
+fun OfflineOperationDao.deleteSubDirIfParentPathMatches(path: String) {
+    val topDir = path.getParentPathFromPath()
+    getAll().forEach {
+        val entityTopDir = it.getParentPathFromPath()
+        if (entityTopDir == topDir) {
+            delete(it)
+        }
+    }
+}
+
 fun OfflineOperationDao.updatePathsIfParentPathMatches(oldPath: String?, newTopDir: String?, parentPath: String?) {
     if (oldPath.isNullOrEmpty() || newTopDir.isNullOrEmpty()) return
 

+ 1 - 0
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -156,6 +156,7 @@ public class FileDataStorageManager {
     }
 
     public void deleteOfflineOperation(OCFile file) {
+        OfflineOperationExtensionsKt.deleteSubDirIfParentPathMatches(offlineOperationDao, file.getDecryptedRemotePath());
         offlineOperationDao.deleteByPath(file.getDecryptedRemotePath());
         removeFile(file, true, true);
     }