Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][multipart] Minor refactor

Neeraj Guptaa49b5f55dd72
diff --git a/mobile/lib/utils/file_uploader.dart b/mobile/lib/utils/file_uploader.dart
index 328c3134e8..b4eab94b9e 100644
--- a/mobile/lib/utils/file_uploader.dart
+++ b/mobile/lib/utils/file_uploader.dart
@@ -487,34 +487,17 @@ class FileUploader {
);
Uint8List? key;
- EncryptionResult? multiPartFileEncResult;
+ EncryptionResult? multiPartFileEncResult = multipartEntryExists
+ ? await _multiPartUploader.getEncryptionResult(
+ lockKey,
+ mediaUploadData.hashData!.fileHash!,
+ collectionID,
+ )
+ : null;
if (isUpdatedFile) {
key = getFileKey(file);
- multiPartFileEncResult = multipartEntryExists
- ? await _multiPartUploader.getEncryptionResult(
- lockKey,
- mediaUploadData.hashData!.fileHash!,
- collectionID,
- )
- : null;
- if (multiPartFileEncResult?.key != null &&
- !listEquals(key, multiPartFileEncResult!.key)) {
- _logger
- .severe("Key mismatch for existing multipart entry, reuploading");
- await _uploadLocks.deleteMultipartTrack(lockKey);
- multipartEntryExists = false;
- multiPartFileEncResult = null;
- }
} else {
- multiPartFileEncResult = multipartEntryExists
- ? await _multiPartUploader.getEncryptionResult(
- lockKey,
- mediaUploadData.hashData!.fileHash!,
- collectionID,
- )
- : null;
key = multiPartFileEncResult?.key;
-
// check if the file is already uploaded and can be mapped to existing
// uploaded file. If map is found, it also returns the corresponding
// mapped or update file entry.
@@ -538,9 +521,17 @@ class FileUploader {
// If the multipart entry exists but the encrypted file doesn't, it means
// that we'll have to reupload as the nonce is lost
if (multipartEntryExists) {
- if (!encryptedFileExists) {
- _logger
- .warning('encrypted file not found for multipart upload entry');
+ final bool updateWithDiffKey = isUpdatedFile &&
+ multiPartFileEncResult != null &&
+ !listEquals(key, multiPartFileEncResult.key);
+ if (!encryptedFileExists || updateWithDiffKey) {
+ if (updateWithDiffKey) {
+ _logger.severe('multiPart update resumed with differentKey');
+ } else {
+ _logger.warning(
+ 'multiPart EncryptedFile missing, discard multipart entry',
+ );
+ }
await _uploadLocks.deleteMultipartTrack(lockKey);
multipartEntryExists = false;
multiPartFileEncResult = null;