Browse Source

Delete all filesystem entries

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
aa85a2e127

+ 8 - 0
src/main/java/com/owncloud/android/datamodel/FilesystemDataProvider.java

@@ -46,6 +46,14 @@ public class FilesystemDataProvider {
         this.contentResolver = contentResolver;
     }
 
+    public int deleteAllEntriesForSyncedFolder(String syncedFolderId) {
+        return contentResolver.delete(
+                ProviderMeta.ProviderTableMeta.CONTENT_URI_FILESYSTEM,
+                ProviderMeta.ProviderTableMeta.FILESYSTEM_SYNCED_FOLDER_ID + " = ?",
+                new String[]{syncedFolderId}
+        );
+    }
+
     public void updateFilesystemFileAsSentForUpload(String path, String syncedFolderId) {
         ContentValues cv = new ContentValues();
         cv.put(ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD, 1);

+ 11 - 0
src/main/java/com/owncloud/android/jobs/AccountRemovalJob.java

@@ -34,6 +34,7 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.FilesystemDataProvider;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.datamodel.UploadsStorageManager;
@@ -44,6 +45,7 @@ import com.owncloud.android.utils.FilesSyncHelper;
 import org.greenrobot.eventbus.EventBus;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 import static android.content.Context.ACCOUNT_SERVICE;
@@ -87,10 +89,13 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
             SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver());
             List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
 
+            List<Long> syncedFolderIds = new ArrayList<>();
+
             for (SyncedFolder syncedFolder : syncedFolders) {
                 if (syncedFolder.getAccount().equals(account.name)) {
                     arbitraryDataProvider.deleteKeyForAccount(FilesSyncHelper.GLOBAL,
                             FilesSyncHelper.SYNCEDFOLDERINITIATED + syncedFolder.getId());
+                    syncedFolderIds.add(syncedFolder.getId());
                 }
             }
 
@@ -100,6 +105,12 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
                     context);
             uploadsStorageManager.removeAccountUploads(account);
 
+            FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(context.getContentResolver());
+
+            for (long syncedFolderId : syncedFolderIds) {
+                filesystemDataProvider.deleteAllEntriesForSyncedFolder(Long.toString(syncedFolderId));
+            }
+
             return Result.SUCCESS;
         } else {
             return Result.FAILURE;