Ver código fonte

Fix deletion behavior

Vishnu Mohandas 4 anos atrás
pai
commit
49af595268
3 arquivos alterados com 19 adições e 1 exclusões
  1. 12 0
      lib/db/files_db.dart
  2. 5 1
      lib/services/sync_service.dart
  3. 2 0
      lib/utils/file_util.dart

+ 12 - 0
lib/db/files_db.dart

@@ -120,6 +120,9 @@ class FilesDB {
     final db = await instance.database;
     final results = await db.query(table,
         where: '$columnGeneratedID = ?', whereArgs: [generatedID]);
+    if (results.isEmpty) {
+      return null;
+    }
     return _convertToFiles(results)[0];
   }
 
@@ -386,6 +389,15 @@ class FilesDB {
     );
   }
 
+  Future<int> deleteLocalFile(String localID) async {
+    final db = await instance.database;
+    return db.delete(
+      table,
+      where: '$columnLocalID =?',
+      whereArgs: [localID],
+    );
+  }
+
   Future<int> deleteFromCollection(int uploadedFileID, int collectionID) async {
     final db = await instance.database;
     return db.delete(

+ 5 - 1
lib/services/sync_service.dart

@@ -218,7 +218,11 @@ class SyncService {
                 .getOrCreateForPath(file.deviceFolder))
             .id;
         final existingFile = await _db.getFile(file.generatedID);
-
+        if (existingFile == null) {
+          // File was deleted locally while being uploaded
+          await _deleteFileOnServer(file.uploadedFileID);
+          continue;
+        }
         if (existingFile.uploadedFileID != null) {
           // The file was uploaded outside this loop
           // Eg: Addition to an album or favorites

+ 2 - 0
lib/utils/file_util.dart

@@ -37,6 +37,8 @@ Future<void> deleteFiles(List<File> files) async {
     if (file.uploadedFileID != null) {
       hasUploadedFiles = true;
       await FilesDB.instance.markForDeletion(file.uploadedFileID);
+    } else {
+      await FilesDB.instance.deleteLocalFile(file.localID);
     }
   }
   await PhotoManager.editor.deleteWithIds(localIDs);