Skip to content

armgit / ente

Public Imported from GitHub
0

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

Enhance file decryption process by introducing temporary decrypted file handling

AmanRajSinghMouryaa6a9d923334a
diff --git a/mobile/apps/locker/lib/services/files/download/file_downloader.dart b/mobile/apps/locker/lib/services/files/download/file_downloader.dart
index f2fc51229e..8452efc277 100644
--- a/mobile/apps/locker/lib/services/files/download/file_downloader.dart
+++ b/mobile/apps/locker/lib/services/files/download/file_downloader.dart
@@ -16,6 +16,12 @@ import 'package:path/path.dart' as p;
final _logger = Logger("FileDownloader");
+String _getTemporaryDecryptedFilePath(EnteFile file) {
+ final String tempDir = Configuration.instance.getTempDirectory();
+ final String safeDisplayName = p.basename(file.displayName);
+ return "$tempDir${file.uploadedFileID}_$safeDisplayName";
+}
+
/// Returns the encrypted offline blob for this device, downloading it only when
/// a usable local copy does not already exist.
Future<File> ensureEncryptedOfflineCopy(
@@ -117,13 +123,14 @@ Future<File?> openFile(
EnteFile file,
Uint8List fileKey, {
ProgressCallback? progressCallback,
+ bool useTemporaryDecryptedFile = false,
}) async {
if (!LockerDB.instance.isFileMarkedOffline(file)) {
return downloadAndDecrypt(
file,
fileKey,
progressCallback: progressCallback,
- shouldUseCache: true,
+ shouldUseCache: !useTemporaryDecryptedFile,
);
}
@@ -134,7 +141,9 @@ Future<File?> openFile(
);
final String logPrefix = 'File-${file.uploadedFileID}:';
final int startTime = DateTime.now().millisecondsSinceEpoch;
- final String decryptedFilePath = getCachedDecryptedFilePath(file);
+ final String decryptedFilePath = useTemporaryDecryptedFile
+ ? _getTemporaryDecryptedFilePath(file)
+ : getCachedDecryptedFilePath(file);
final File decryptedFile = File(decryptedFilePath);
final int sizeInBytes = file.fileSize ?? await offlineEncryptedFile.length();
@@ -196,7 +205,7 @@ Future<File?> openFile(
file,
fileKey,
progressCallback: progressCallback,
- shouldUseCache: true,
+ shouldUseCache: !useTemporaryDecryptedFile,
);
}
@@ -221,10 +230,9 @@ Future<File?> downloadAndDecrypt(
bool usingCachedEncryptedFile = false;
bool downloadedFreshEncryptedFile = false;
- final String safeDisplayName = p.basename(file.displayName);
final String decryptedFilePath = shouldUseCache
? cachedDecryptedFilePath
- : "$tempDir${file.uploadedFileID}_$safeDisplayName";
+ : _getTemporaryDecryptedFilePath(file);
final File decryptedFile = File(decryptedFilePath);
final startTime = DateTime.now().millisecondsSinceEpoch;
diff --git a/mobile/apps/locker/lib/utils/file_util.dart b/mobile/apps/locker/lib/utils/file_util.dart
index dc4a33c925..5a4d5af2a2 100644
--- a/mobile/apps/locker/lib/utils/file_util.dart
+++ b/mobile/apps/locker/lib/utils/file_util.dart
@@ -232,6 +232,7 @@ class FileUtil {
final decryptedFile = await file_downloader.openFile(
file,
fileKey,
+ useTemporaryDecryptedFile: true,
progressCallback: (downloaded, total) {
if (total > 0 && downloaded >= 0) {
final percentage = ((downloaded / total) * 100).clamp(0, 100).round();