ソースを参照

minor refactor

Neeraj Gupta 2 年 前
コミット
48dad9a397

+ 5 - 6
lib/ui/tools/debug/path_storage_viewer.dart

@@ -39,7 +39,7 @@ class PathStorageViewer extends StatefulWidget {
 }
 
 class _PathStorageViewerState extends State<PathStorageViewer> {
-  Map<String, int>? _logs;
+  Map<String, int>? _sizeAndFileCountInfo;
 
   @override
   void initState() {
@@ -48,10 +48,9 @@ class _PathStorageViewerState extends State<PathStorageViewer> {
   }
 
   void _initLogs() {
-    debugPrint("Calculate for path ${widget.item.title}");
     directoryStat(widget.item.path).then((logs) {
       setState(() {
-        _logs = logs;
+        _sizeAndFileCountInfo = logs;
       });
     });
   }
@@ -62,11 +61,11 @@ class _PathStorageViewerState extends State<PathStorageViewer> {
   }
 
   Widget _getBody() {
-    if (_logs == null) {
+    if (_sizeAndFileCountInfo == null) {
       return const EnteLoadingWidget();
     }
-    final int fileCount = _logs!["fileCount"] ?? -1;
-    final int size = _logs!['size'] ?? 0;
+    final int fileCount = _sizeAndFileCountInfo!["fileCount"] ?? -1;
+    final int size = _sizeAndFileCountInfo!['size'] ?? 0;
 
     return MenuItemWidget(
       alignCaptionedTextToLeft: true,

+ 3 - 0
lib/utils/directory_content.dart

@@ -27,6 +27,9 @@ Future<Map<String, int>> directoryStat(String dirPath) async {
 Future<void> deleteDirectoryContents(String directoryPath) async {
   // Mark variables as final if they don't need to be modified
   final directory = Directory(directoryPath);
+  if (!(await directory.exists())) {
+    return;
+  }
   final contents = await directory.list().toList();
 
   // Iterate through the list and delete each file or directory