From 1d081795ebcd1d2f0b9ee257511bd4d0cc4ac30f Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 6 Jan 2023 10:22:19 +0530 Subject: [PATCH 1/3] Fix: Conditional check for null value --- lib/utils/file_util.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/file_util.dart b/lib/utils/file_util.dart index ebdc6a285..892f0b307 100644 --- a/lib/utils/file_util.dart +++ b/lib/utils/file_util.dart @@ -51,8 +51,8 @@ Future getFile( ); // do not cache origin file for IOS as they are immediately deleted // after usage - if (!(isOrigin && Platform.isIOS && diskFile != null)) { - FileLruCache.put(key, diskFile!); + if (!(isOrigin && Platform.isIOS) && diskFile != null) { + FileLruCache.put(key, diskFile); } return diskFile; } From b3bc236139fd2c55fe0e7ec62d1c8d87c633a536 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 6 Jan 2023 10:47:00 +0530 Subject: [PATCH 2/3] Fix mapping of files during restore --- lib/services/collections_service.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index 631b630e9..87d394650 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -884,6 +884,8 @@ class CollectionsService { final params = {}; params["collectionID"] = toCollectionID; final toCollectionKey = getCollectionKey(toCollectionID); + final Set existingLocalIDS = + await FilesDB.instance.getExistingLocalFileIDs(); final batchedFiles = files.chunks(batchSize); for (final batch in batchedFiles) { params["files"] = []; @@ -892,6 +894,11 @@ class CollectionsService { file.generatedID = null; // So that a new entry is created in the FilesDB file.collectionID = toCollectionID; + // During restore, if trash file local ID is not present in currently + // imported files, treat the file as deleted from device + if (file.localID != null && !existingLocalIDS.contains(file.localID)) { + file.localID = null; + } final encryptedKeyData = CryptoUtil.encryptSync(key, toCollectionKey); file.encryptedKey = Sodium.bin2base64(encryptedKeyData.encryptedData!); file.keyDecryptionNonce = Sodium.bin2base64(encryptedKeyData.nonce!); From 54d14627b7b9e13a73d2d00a6b48722c7e2eb2ef Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 6 Jan 2023 10:49:46 +0530 Subject: [PATCH 3/3] Fix: Local id value for trash diff --- lib/services/trash_sync_service.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/services/trash_sync_service.dart b/lib/services/trash_sync_service.dart index 961436ef2..b687f56e9 100644 --- a/lib/services/trash_sync_service.dart +++ b/lib/services/trash_sync_service.dart @@ -5,6 +5,7 @@ import 'package:logging/logging.dart'; import 'package:photos/core/constants.dart'; import 'package:photos/core/event_bus.dart'; import 'package:photos/core/network.dart'; +import 'package:photos/db/files_db.dart'; import 'package:photos/db/trash_db.dart'; import 'package:photos/events/collection_updated_event.dart'; import 'package:photos/events/force_reload_trash_page_event.dart'; @@ -40,9 +41,18 @@ class TrashSyncService { bool isLocalTrashUpdated = false; _logger.fine('sync trash sinceTime : $lastSyncTime'); final diff = await _diffFetcher.getTrashFilesDiff(lastSyncTime); + Set? localFileIDs; if (diff.trashedFiles.isNotEmpty) { isLocalTrashUpdated = true; + localFileIDs ??= await FilesDB.instance.getExistingLocalFileIDs(); _logger.fine("inserting ${diff.trashedFiles.length} items in trash"); + // During sync, if trash file local ID is not present in currently + // imported files, treat the file as deleted from device + for (var trash in diff.trashedFiles) { + if (trash.localID != null && !localFileIDs.contains(trash.localID)) { + trash.localID = null; + } + } await _trashDB.insertMultiple(diff.trashedFiles); } if (diff.deletedUploadIDs.isNotEmpty) {