Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][config] Skip deleting temp encrypted files for upload

Neeraj Gupta2de5b641a710
diff --git a/mobile/lib/core/configuration.dart b/mobile/lib/core/configuration.dart
index cde766b1e0..4d2a4bf264 100644
--- a/mobile/lib/core/configuration.dart
+++ b/mobile/lib/core/configuration.dart
@@ -103,20 +103,7 @@ class Configuration {
_documentsDirectory = (await getApplicationDocumentsDirectory()).path;
_tempDocumentsDirPath = _documentsDirectory + "/temp/";
final tempDocumentsDir = Directory(_tempDocumentsDirPath);
- try {
- final currentTime = DateTime.now().microsecondsSinceEpoch;
- if (tempDocumentsDir.existsSync() &&
- (_preferences.getInt(lastTempFolderClearTimeKey) ?? 0) <
- (currentTime - kTempFolderDeletionTimeBuffer)) {
- await tempDocumentsDir.delete(recursive: true);
- await _preferences.setInt(lastTempFolderClearTimeKey, currentTime);
- _logger.info("Cleared temp folder");
- } else {
- _logger.info("Skipping temp folder clear");
- }
- } catch (e) {
- _logger.warning(e);
- }
+ await _cleanUpStaleFiles(tempDocumentsDir);
tempDocumentsDir.createSync(recursive: true);
final tempDirectoryPath = (await getTemporaryDirectory()).path;
_thumbnailCacheDirectory = tempDirectoryPath + "/thumbnail-cache";
@@ -144,6 +131,40 @@ class Configuration {
SuperLogging.setUserID(await _getOrCreateAnonymousUserID()).ignore();
}
+ // _cleanUpStaleFiles deletes all files in the temp directory that are older
+ // than kTempFolderDeletionTimeBuffer except the the temp encrypted files for upload.
+ // Those file are deleted by file uploader after the upload is complete or those
+ // files are not being used / tracked.
+ Future<void> _cleanUpStaleFiles(Directory tempDocumentsDir) async {
+ try {
+ final currentTime = DateTime.now().microsecondsSinceEpoch;
+ if (tempDocumentsDir.existsSync() &&
+ (_preferences.getInt(lastTempFolderClearTimeKey) ?? 0) <
+ (currentTime - kTempFolderDeletionTimeBuffer)) {
+ // list all files in the temp directory
+ final files = tempDocumentsDir.listSync();
+ for (final file in files) {
+ if (file is File) {
+ if (file.path.contains(uploadTempFilePrefix)) {
+ continue;
+ }
+ _logger.info("Deleting file: ${file.path}");
+ await file.delete();
+ } else if (file is Directory) {
+ await file.delete(recursive: true);
+ }
+ }
+ // await tempDocumentsDir.delete(recursive: true);
+ await _preferences.setInt(lastTempFolderClearTimeKey, currentTime);
+ _logger.info("Cleared temp folder");
+ } else {
+ _logger.info("Skipping temp folder clear");
+ }
+ } catch (e) {
+ _logger.warning(e);
+ }
+ }
+
Future<void> logout({bool autoLogout = false}) async {
if (SyncService.instance.isSyncInProgress()) {
SyncService.instance.stopSync();