[geary/wip/714104-refine-account-dialog: 28/69] Add priority arg to Geary.Files.recursive_delete_async().



commit fa3b8fa53fd38e0f691047ce1f9ff744ce625ccb
Author: Michael James Gratton <mike vee net>
Date:   Sun Jun 17 13:58:33 2018 +1000

    Add priority arg to Geary.Files.recursive_delete_async().

 src/client/accounts/account-manager.vala           |  8 +++--
 .../imap-engine/imap-engine-generic-account.vala   | 22 +++++++++-----
 src/engine/util/util-files.vala                    | 34 +++++++++++++++-------
 test/engine/imap-db/imap-db-attachment-test.vala   |  7 ++---
 test/engine/imap-db/imap-db-database-test.vala     |  6 ++--
 5 files changed, 51 insertions(+), 26 deletions(-)
---
diff --git a/src/client/accounts/account-manager.vala b/src/client/accounts/account-manager.vala
index 949c3f12..9e654466 100644
--- a/src/client/accounts/account-manager.vala
+++ b/src/client/accounts/account-manager.vala
@@ -555,11 +555,15 @@ public class AccountManager : GLib.Object {
                                      GLib.Cancellable? cancellable)
         throws GLib.Error {
         if (info.data_dir != null) {
-            yield Geary.Files.recursive_delete_async(info.data_dir, cancellable);
+            yield Geary.Files.recursive_delete_async(
+                info.data_dir, GLib.Priority.DEFAULT, cancellable
+            );
         }
 
         if (info.config_dir != null) {
-            yield Geary.Files.recursive_delete_async(info.config_dir, cancellable);
+            yield Geary.Files.recursive_delete_async(
+                info.config_dir, GLib.Priority.DEFAULT, cancellable
+            );
         }
 
         SecretMediator? mediator = info.imap.mediator as SecretMediator;
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index f21e6c2e..e2ff420c 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -229,17 +229,25 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         File attachments_dir;
         ImapDB.Account.get_imap_db_storage_locations(information.data_dir, out db_file,
             out attachments_dir);
-        
+
         if (yield Files.query_exists_async(db_file, cancellable)) {
-            message("%s: Deleting database file %s...", to_string(), db_file.get_path());
-            yield db_file.delete_async(Priority.DEFAULT, cancellable);
+            message(
+                "%s: Deleting database file %s...",
+                to_string(), db_file.get_path()
+            );
+            yield db_file.delete_async(GLib.Priority.DEFAULT, cancellable);
         }
-        
+
         if (yield Files.query_exists_async(attachments_dir, cancellable)) {
-            message("%s: Deleting attachments directory %s...", to_string(), attachments_dir.get_path());
-            yield Files.recursive_delete_async(attachments_dir, cancellable);
+            message(
+                "%s: Deleting attachments directory %s...",
+                to_string(), attachments_dir.get_path()
+            );
+            yield Files.recursive_delete_async(
+                attachments_dir, GLib.Priority.DEFAULT, cancellable
+            );
         }
-        
+
         message("%s: Rebuild complete", to_string());
     }
 
diff --git a/src/engine/util/util-files.vala b/src/engine/util/util-files.vala
index 2869cf3e..386d0f25 100644
--- a/src/engine/util/util-files.vala
+++ b/src/engine/util/util-files.vala
@@ -14,7 +14,9 @@ private const int RECURSIVE_DELETE_BATCH_SIZE = 50;
  * This method is designed to keep chugging along even if an error occurs.
  * If this method is called with a file, it will simply be deleted.
  */
-public async void recursive_delete_async(File folder, Cancellable? cancellable = null) {
+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 {
@@ -29,8 +31,12 @@ public async void recursive_delete_async(File folder, Cancellable? cancellable =
     if (file_type == FileType.DIRECTORY) {
         FileEnumerator? enumerator = null;
         try {
-            enumerator = yield folder.enumerate_children_async(FileAttribute.STANDARD_NAME,
-                FileQueryInfoFlags.NOFOLLOW_SYMLINKS, Priority.DEFAULT, cancellable);
+            enumerator = yield folder.enumerate_children_async(
+                FileAttribute.STANDARD_NAME,
+                FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
+                priority,
+                cancellable
+            );
         } catch (Error e) {
             debug("Error enumerating files for deletion: %s", e.message);
         }
@@ -39,14 +45,22 @@ public async void recursive_delete_async(File folder, Cancellable? cancellable =
         if (enumerator != null) {
             try {
                 while (true) {
-                    List<FileInfo>? info_list = yield 
enumerator.next_files_async(RECURSIVE_DELETE_BATCH_SIZE,
-                        Priority.DEFAULT, cancellable);
+                    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()), cancellable);
+                    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);
@@ -56,10 +70,10 @@ public async void recursive_delete_async(File folder, Cancellable? cancellable =
             }
         }
     }
-    
+
     // Children have been deleted, it's now safe to delete this file/folder.
     try {
-        yield folder.delete_async(Priority.DEFAULT, cancellable);
+        yield folder.delete_async(priority, cancellable);
     } catch (Error e) {
         debug("Error removing file: %s", e.message);
     }
diff --git a/test/engine/imap-db/imap-db-attachment-test.vala 
b/test/engine/imap-db/imap-db-attachment-test.vala
index 2211655b..1bfa02a3 100644
--- a/test/engine/imap-db/imap-db-attachment-test.vala
+++ b/test/engine/imap-db/imap-db-attachment-test.vala
@@ -144,12 +144,11 @@ CREATE TABLE MessageAttachmentTable (
         this.db.close();
         this.db = null;
 
-        Geary.Files.recursive_delete_async.begin(
-            this.tmp_dir,
-            null,
+        Files.recursive_delete_async.begin(
+            this.tmp_dir, GLib.Priority.DEFAULT, null,
             (obj, res) => { async_complete(res); }
         );
-        Geary.Files.recursive_delete_async.end(async_result());
+        Files.recursive_delete_async.end(async_result());
         this.tmp_dir = null;
     }
 
diff --git a/test/engine/imap-db/imap-db-database-test.vala b/test/engine/imap-db/imap-db-database-test.vala
index 1a7cdc19..892d2815 100644
--- a/test/engine/imap-db/imap-db-database-test.vala
+++ b/test/engine/imap-db/imap-db-database-test.vala
@@ -121,11 +121,11 @@ class Geary.ImapDB.DatabaseTest : TestCase {
         // Need to close it again to stop the GC process running
         db.close();
 
-        Geary.Files.recursive_delete_async.begin(
-            tmp_dir, null,
+        Files.recursive_delete_async.begin(
+            tmp_dir, GLib.Priority.DEFAULT, null,
             (obj, res) => { async_complete(res); }
         );
-        Geary.Files.recursive_delete_async.end(async_result());
+        Files.recursive_delete_async.end(async_result());
     }
 
 


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