[mob][multipart] Avoid deleting multipart enc files if upload is in progress

This commit is contained in:
Neeraj Gupta
2024-05-08 17:04:39 +05:30
parent 92357f697d
commit f4845baa9b
3 changed files with 29 additions and 18 deletions

View File

@@ -327,8 +327,23 @@ class FileUploader {
});
if (filesToDelete.isNotEmpty) {
_logger.info('Deleting ${filesToDelete.length} stale upload files ');
final fileNameToLastAttempt =
await _uploadLocks.getFileNameToLastAttemptedAtMap();
for (final file in filesToDelete) {
await file.delete();
final fileName =
file.path.split('/').last.replaceAll(uploadTempFilePrefix, '');
final lastAttemptTime = fileNameToLastAttempt[fileName] != null
? DateTime.fromMillisecondsSinceEpoch(
fileNameToLastAttempt[fileName]!,
)
: null;
if (lastAttemptTime == null ||
DateTime.now().difference(lastAttemptTime).inDays > 1) {
await file.delete();
} else {
_logger.info(
'Skipping file $fileName as it was attempted recently on $lastAttemptTime');
}
}
}