Ver código fonte

Fix potential NPE during upload

Neeraj Gupta 2 anos atrás
pai
commit
79369a2afd
1 arquivos alterados com 7 adições e 5 exclusões
  1. 7 5
      lib/utils/file_uploader.dart

+ 7 - 5
lib/utils/file_uploader.dart

@@ -3,7 +3,6 @@ import 'dart:collection';
 import 'dart:convert';
 import 'dart:io' as io;
 import 'dart:math';
-import 'dart:typed_data';
 
 import 'package:collection/collection.dart';
 import 'package:connectivity_plus/connectivity_plus.dart';
@@ -306,10 +305,11 @@ class FileUploader {
       debugPrint("File is already uploaded ${fileOnDisk.tag}");
       return fileOnDisk;
     }
+    final String lockKey = file.localID!;
 
     try {
       await _uploadLocks.acquireLock(
-        file.localID!,
+        lockKey,
         _processType.toString(),
         DateTime.now().microsecondsSinceEpoch,
       );
@@ -502,6 +502,7 @@ class FileUploader {
         file,
         encryptedFilePath,
         encryptedThumbnailPath,
+        lockKey: lockKey,
       );
     }
   }
@@ -642,8 +643,9 @@ class FileUploader {
     bool uploadHardFailure,
     File file,
     String encryptedFilePath,
-    String encryptedThumbnailPath,
-  ) async {
+    String encryptedThumbnailPath, {
+    required String lockKey,
+  }) async {
     if (mediaUploadData != null && mediaUploadData.sourceFile != null) {
       // delete the file from app's internal cache if it was copied to app
       // for upload. On iOS, only remove the file from photo_manager/app cache
@@ -661,7 +663,7 @@ class FileUploader {
     if (io.File(encryptedThumbnailPath).existsSync()) {
       await io.File(encryptedThumbnailPath).delete();
     }
-    await _uploadLocks.releaseLock(file.localID!, _processType.toString());
+    await _uploadLocks.releaseLock(lockKey, _processType.toString());
   }
 
   Future _onInvalidFileError(File file, InvalidFileError e) async {