diff --git a/lib/core/service/file_service.dart b/lib/core/service/file_service.dart index a8c0011..db137bf 100644 --- a/lib/core/service/file_service.dart +++ b/lib/core/service/file_service.dart @@ -85,6 +85,16 @@ class FileService { await scanDir?.delete(recursive: true); await tempDir.delete(recursive: true); } + + static Future clearDirectoryContent(PaperlessDirectoryType type) async { + final dir = await getDirectory(type); + + if (dir == null || !(await dir.exists())) { + return; + } + + await Future.wait(dir.listSync().map((item) => item.delete())); + } } enum PaperlessDirectoryType { diff --git a/lib/main.dart b/lib/main.dart index 570bf7c..99f0594 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -98,9 +98,7 @@ void main() async { final connectivityCubit = ConnectivityCubit(connectivityStatusService); // Remove temporarily downloaded files. - for (var item in (await FileService.temporaryDirectory).listSync()) { - item.deleteSync(recursive: true); - } + await FileService.clearDirectoryContent(PaperlessDirectoryType.temporary); // Load application settings and stored authentication data await connectivityCubit.initialize();