[geary/mjog/1147-startup-warning: 1/2] Geary.Util.Files.recursive_delete_async: Throw rather than log errors




commit 7100598c56fe141d9afd5a239cdffaee5bf78635
Author: Michael Gratton <mike vee net>
Date:   Wed Feb 10 22:19:33 2021 +1100

    Geary.Util.Files.recursive_delete_async: Throw rather than log errors

 src/engine/util/util-files.vala | 68 ++++++++++++++---------------------------
 1 file changed, 23 insertions(+), 45 deletions(-)
---
diff --git a/src/engine/util/util-files.vala b/src/engine/util/util-files.vala
index 836ed5278..eafcd2812 100644
--- a/src/engine/util/util-files.vala
+++ b/src/engine/util/util-files.vala
@@ -16,67 +16,45 @@ private const int RECURSIVE_DELETE_BATCH_SIZE = 50;
  */
 public async void recursive_delete_async(GLib.File folder,
                                          int priority = GLib.Priority.DEFAULT,
-                                         GLib.Cancellable? cancellable = null) {
-    // If this is a folder, recurse children.
-    FileType file_type = FileType.UNKNOWN;
-    try {
-        file_type = yield query_file_type_async(folder, true, cancellable);
-    } catch (Error err) {
-        debug("Unable to get file type of %s: %s", folder.get_path(), err.message);
+                                         GLib.Cancellable? cancellable = null)
+    throws GLib.Error {
+    GLib.FileType type = yield query_file_type_async(folder, true, cancellable);
 
-        if (err is IOError.CANCELLED)
-            return;
-    }
-
-    if (file_type == FileType.DIRECTORY) {
-        FileEnumerator? enumerator = null;
-        try {
-            enumerator = yield folder.enumerate_children_async(
+    // If this is a folder, recurse children.
+    if (type == DIRECTORY) {
+        FileEnumerator? enumerator = yield folder.enumerate_children_async(
                 FileAttribute.STANDARD_NAME,
-                FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
+                NOFOLLOW_SYMLINKS,
                 priority,
                 cancellable
-            );
-        } catch (Error e) {
-            debug("Error enumerating files for deletion: %s", e.message);
-        }
+        );
 
         // Iterate the enumerated files in batches.
         if (enumerator != null) {
-            try {
-                while (true) {
-                    List<FileInfo>? info_list = yield enumerator.next_files_async(
-                        RECURSIVE_DELETE_BATCH_SIZE,
+            while (true) {
+                List<FileInfo>? info_list = yield enumerator.next_files_async(
+                    RECURSIVE_DELETE_BATCH_SIZE,
+                    priority,
+                    cancellable
+                );
+                if (info_list == null) {
+                    break; // Stop condition.
+                }
+
+                // Recursive step.
+                foreach (FileInfo info in info_list) {
+                    yield recursive_delete_async(
+                        folder.get_child(info.get_name()),
                         priority,
                         cancellable
                     );
-                    if (info_list == null)
-                        break; // Stop condition.
-
-                    // Recursive step.
-                    foreach (FileInfo info in info_list) {
-                        yield recursive_delete_async(
-                            folder.get_child(info.get_name()),
-                            priority,
-                            cancellable
-                        );
-                    }
                 }
-            } catch (Error e) {
-                debug("Error enumerating batch of files: %s", e.message);
-
-                if (e is IOError.CANCELLED)
-                    return;
             }
         }
     }
 
     // Children have been deleted, it's now safe to delete this file/folder.
-    try {
-        yield folder.delete_async(priority, cancellable);
-    } catch (Error e) {
-        debug("Error removing file: %s", e.message);
-    }
+    yield folder.delete_async(priority, cancellable);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]