Merge pull request #776 from ente-io/bug_fixes
Trash/Restore: Bug fixes
This commit is contained in:
commit
ac8eb5fdad
3 changed files with 19 additions and 2 deletions
|
@ -884,6 +884,8 @@ class CollectionsService {
|
|||
final params = <String, dynamic>{};
|
||||
params["collectionID"] = toCollectionID;
|
||||
final toCollectionKey = getCollectionKey(toCollectionID);
|
||||
final Set<String> 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!);
|
||||
|
|
|
@ -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<String>? 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) {
|
||||
|
|
|
@ -51,8 +51,8 @@ Future<io.File?> 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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue