diff --git a/lib/db/files_db.dart b/lib/db/files_db.dart index db4ae89aa..38b7b73db 100644 --- a/lib/db/files_db.dart +++ b/lib/db/files_db.dart @@ -770,12 +770,17 @@ class FilesDB { return uploadedFileIDs; } - Future getUploadedFileInAnyCollection(int uploadedFileID) async { + Future getUploadedLocalFileInAnyCollection( + int uploadedFileID, + int userID, + ) async { final db = await instance.database; final results = await db.query( filesTable, - where: '$columnUploadedFileID = ?', + where: '$columnLocalID IS NOT NULL AND $columnOwnerID = ? AND ' + '$columnUploadedFileID = ?', whereArgs: [ + userID, uploadedFileID, ], limit: 1, diff --git a/lib/services/remote_sync_service.dart b/lib/services/remote_sync_service.dart index e80a15b4e..5de50955a 100644 --- a/lib/services/remote_sync_service.dart +++ b/lib/services/remote_sync_service.dart @@ -519,7 +519,10 @@ class RemoteSyncService { .info("Skipping some updated files as we are throttling uploads"); break; } - final file = await _db.getUploadedFileInAnyCollection(uploadedFileID); + final file = await _db.getUploadedLocalFileInAnyCollection( + uploadedFileID, + ownerID, + ); if (file != null) { _uploadFile(file, file.collectionID!, futures); } diff --git a/lib/utils/file_uploader.dart b/lib/utils/file_uploader.dart index d4c79bf94..4cf34f189 100644 --- a/lib/utils/file_uploader.dart +++ b/lib/utils/file_uploader.dart @@ -117,6 +117,9 @@ class FileUploader { // upload future will return null as File when the file entry is deleted // locally because it's already present in the destination collection. Future upload(File file, int collectionID) { + if (file.localID == null || file.localID!.isEmpty) { + return Future.error(Exception("file's localID can not be null or empty")); + } // If the file hasn't been queued yet, queue it _totalCountInUploadSession++; if (!_queue.containsKey(file.localID)) {