TF-2311 Only delete the folder when it exists

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit d3cf489cbc71bfa0c05d0c633136d504d3d9dfdd)
This commit is contained in:
dab246
2023-11-14 17:20:43 +07:00
committed by Dat Vu
parent eb3e27ce91
commit 5871225537
2 changed files with 9 additions and 5 deletions
+4 -2
View File
@@ -98,13 +98,15 @@ class FileUtils {
return File(internalStorageDirPath).exists(); return File(internalStorageDirPath).exists();
} }
void removeFolder(String folderName) async { Future<void> removeFolder(String folderName) async {
try { try {
String folderPath = (await getApplicationDocumentsDirectory()).absolute.path; String folderPath = (await getApplicationDocumentsDirectory()).absolute.path;
folderPath = '$folderPath/$folderName'; folderPath = '$folderPath/$folderName';
log('FileUtils::removeFolder():folderPath: $folderPath'); log('FileUtils::removeFolder():folderPath: $folderPath');
final dir = Directory(folderPath); final dir = Directory(folderPath);
dir.deleteSync(recursive: true); if (await dir.exists()) {
await dir.delete(recursive: true);
}
} catch (e) { } catch (e) {
logError('FileUtils::removeFolder():EXCEPTION: $e'); logError('FileUtils::removeFolder():EXCEPTION: $e');
} }
+5 -3
View File
@@ -128,10 +128,12 @@ class CachingManager {
return await HiveCacheConfig().closeHive(); return await HiveCacheConfig().closeHive();
} }
void clearAllFileInStorage() { Future<void> clearAllFileInStorage() async {
if (PlatformInfo.isMobile) { if (PlatformInfo.isMobile) {
_fileUtils.removeFolder(CachingConstants.newEmailsContentFolderName); await Future.wait([
_fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName); _fileUtils.removeFolder(CachingConstants.newEmailsContentFolderName),
_fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName),
]);
} }
} }