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:
@@ -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');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user