[geary/wip/delete-folder-714357: 1/4] WIP



commit 54dc88a0f79c475a2aa690fa929fef67c6465d41
Author: Charles Lindsay <chaz yorba org>
Date:   Tue Feb 11 18:38:50 2014 -0800

    WIP

 src/engine/imap-db/imap-db-account.vala |   32 +++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index dde70cb..97892bf 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -213,6 +213,31 @@ private class Geary.ImapDB.Account : BaseObject {
         }, cancellable);
     }
     
+    public async void delete_folder_async(Geary.Folder folder, Cancellable? cancellable)
+        throws Error {
+        check_open();
+        
+        // TODO: wait for the folder to close?  Is it possible for it to even be open?
+        
+        Geary.FolderPath path = folder.path;
+        
+        yield db.exec_transaction_async(Db.TransactionType.RW, (cx) => {
+            int64 folder_id;
+            do_fetch_folder_id(cx, path, false, out folder_id, cancellable);
+            if (folder_id == Db.INVALID_ROWID)
+                return Db.TransactionOutcome.ROLLBACK;
+            
+            if (do_has_children(folder_id, cancellable)) {
+                debug("Can't delete folder %s because it has children", folder.to_string());
+                return Db.TransactionOutcome.ROLLBACK;
+            }
+            
+            do_delete_folder(cx, folder_id, cancellable);
+            
+            return Db.TransactionOutcome.COMMIT;
+        }, cancellable);
+    }
+    
     /**
      * Only updates folder's STATUS message count, attributes, recent, and unseen; UIDVALIDITY and UIDNEXT
      * updated when the folder is SELECT/EXAMINED (see update_folder_select_examine_async()) unless
@@ -1234,6 +1259,13 @@ private class Geary.ImapDB.Account : BaseObject {
         return do_fetch_folder_id(cx, path.get_parent(), create, out parent_id, cancellable);
     }
     
+    private bool do_has_children(Db.Connection cx, int64 folder_id, Cancellable? cancellable) throws Error {
+        Db.Statement stmt = cx.prepare("SELECT 1 FROM FolderTable WHERE parent_id = ?");
+        stmt.bind_rowid(0, folder_id);
+        Db.Result result = stmt.exec(cancellable);
+        return !result.finished;
+    }
+    
     // Turn the collection of folder paths into actual folder ids.  As a
     // special case, if "folderless" or orphan emails are to be blacklisted,
     // set the out bool to true.


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