Bug 1513267 - rename nsIMsgFolder::Delete method to deleteStorage (what it really does) and document the other folder deleting methods. r=jorgk
authoraceman <acelists@atlas.sk>
Sun, 27 Oct 2019 13:29:00 +0100
changeset 37369 c6454775a43361a051100864556d44354dd4380e
parent 37368 37638cf21b5671fc5d2aeb7a4da7f6acbacc42e3
child 37370 74bd1f64906accd6d0056cc29fb77fec292ffba7
push id396
push userclokep@gmail.com
push dateMon, 06 Jan 2020 23:11:57 +0000
reviewersjorgk
bugs1513267
Bug 1513267 - rename nsIMsgFolder::Delete method to deleteStorage (what it really does) and document the other folder deleting methods. r=jorgk
mail/test/mozmill/session-store/test-session-store.js
mailnews/base/public/nsIMsgFolder.idl
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapMailFolder.h
mailnews/local/src/nsMsgBrkMBoxStore.cpp
mailnews/local/src/nsMsgMaildirStore.cpp
mailnews/news/src/nsNewsFolder.cpp
mailnews/news/src/nsNewsFolder.h
--- a/mail/test/mozmill/session-store/test-session-store.js
+++ b/mail/test/mozmill/session-store/test-session-store.js
@@ -124,18 +124,18 @@ function setupModule(module) {
   SessionStoreManager.stopPeriodicSave();
 
   // Opt out of calendar promotion so we don't show the "ligthing now
   // integrated" notification bar (which gives us unexpected heights).
   Services.prefs.setBoolPref("calendar.integration.notify", false);
 }
 
 function teardownModule(module) {
-  folderA.Delete();
-  folderB.Delete();
+  folderA.server.rootFolder.propagateDelete(folderA, true, null);
+  folderB.server.rootFolder.propagateDelete(folderB, true, null);
   Services.prefs.clearUserPref("calendar.integration.notify");
 }
 
 function test_periodic_session_persistence_simple() {
   // delete the session file if it exists
   let sessionFile = SessionStoreManager.sessionFile;
   if (sessionFile.exists()) {
     sessionFile.remove(false);
--- a/mailnews/base/public/nsIMsgFolder.idl
+++ b/mailnews/base/public/nsIMsgFolder.idl
@@ -172,21 +172,49 @@ interface nsIMsgFolder : nsISupports {
    * Close and backup a folder database prior to reparsing
    *
    * @param  newName  New name of the corresponding message folder.
    *                  Used in rename to set the file name to match the renamed
    *                  folder. Set to empty to use the existing folder name.
    */
   void closeAndBackupFolderDB(in ACString newName);
 
-  void Delete();
+
+  /**
+   * Delete the backing store of the folder, but not the folder itself.
+   */
+  [noscript]
+  void deleteStorage();
 
+  /**
+   * Delete the given subfolders of this folder.
+   *
+   * @param folders    an array of subfolders to delete
+   * @param msgWindow  msgWindow to display status feedback in
+   */
   void deleteSubFolders(in nsIArray folders, in nsIMsgWindow msgWindow);
+
+  /**
+   * Delete the given subfolder of this folder.
+   * It does not need to be a direct child.
+   *
+   * @param folder         a child subfolder to delete
+   * @param deleteStorage  whether to also delete the folder storage on disk
+   * @param msgWindow      msgWindow to display status feedback in
+   */
   void propagateDelete(in nsIMsgFolder folder, in boolean deleteStorage,
                        in nsIMsgWindow msgWindow);
+
+  /**
+   * Delete the folder and all of its subfolders.
+   *
+   * @param deleteStorage  whether to also delete the folder storage on disk
+   * @param msgWindow      msgWindow to display status feedback in
+   */
+  [noscript]
   void recursiveDelete(in boolean deleteStorage, in nsIMsgWindow msgWindow);
 
   /**
    * Create a subfolder of the current folder with the passed in name.
    * For IMAP, this will be an async operation and the folder won't exist
    * until it is created on the server.
    *
    * @param folderName name of the folder to create.
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -3335,17 +3335,17 @@ NS_IMETHODIMP nsMsgDBFolder::GetChildWit
 }
 
 NS_IMETHODIMP nsMsgDBFolder::GetShowDeletedMessages(bool *showDeletedMessages) {
   NS_ENSURE_ARG_POINTER(showDeletedMessages);
   *showDeletedMessages = false;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgDBFolder::Delete() {
+NS_IMETHODIMP nsMsgDBFolder::DeleteStorage() {
   ForceDBClosed();
 
   // Delete the .msf file.
   // NOTE: this doesn't remove .msf files in subfolders, but
   // both nsMsgBrkMBoxStore::DeleteFolder() and
   // nsMsgMaildirStore::DeleteFolder() will remove those .msf files
   // as a side-effect of deleting the .sbd directory.
   nsCOMPtr<nsIFile> summaryFile;
@@ -3358,19 +3358,17 @@ NS_IMETHODIMP nsMsgDBFolder::Delete() {
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Ask the msgStore to delete the actual storage (mbox, maildir or whatever
   // else may be supported in future).
   nsCOMPtr<nsIMsgPluggableStore> msgStore;
   rv = GetMsgStore(getter_AddRefs(msgStore));
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = msgStore->DeleteFolder(this);
-
-  return rv;
+  return msgStore->DeleteFolder(this);
 }
 
 NS_IMETHODIMP nsMsgDBFolder::DeleteSubFolders(nsIArray *folders,
                                               nsIMsgWindow *msgWindow) {
   uint32_t count;
   nsresult rv = folders->GetLength(&count);
   for (uint32_t i = 0; i < count; i++) {
     nsCOMPtr<nsIMsgFolder> folder(do_QueryElementAt(folders, i, &rv));
@@ -3414,20 +3412,21 @@ NS_IMETHODIMP nsMsgDBFolder::PropagateDe
 }
 
 NS_IMETHODIMP nsMsgDBFolder::RecursiveDelete(bool deleteStorage,
                                              nsIMsgWindow *msgWindow) {
   // If deleteStorage is true, recursively deletes disk storage for this folder
   // and all its subfolders.
   // Regardless of deleteStorage, always unlinks them from the children lists
   // and frees memory for the subfolders but NOT for _this_
-
-  nsresult status = NS_OK;
+  // and does not remove _this_ from the parent's list of children.
+
+  nsresult rv = NS_OK;
+
   nsCOMPtr<nsIFile> dbPath;
-
   // first remove the deleted folder from the folder cache;
   nsresult result = GetFolderCacheKey(getter_AddRefs(dbPath));
 
   nsCOMPtr<nsIMsgAccountManager> accountMgr =
       do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &result);
   if (NS_SUCCEEDED(result)) {
     nsCOMPtr<nsIMsgFolderCache> folderCache;
     result = accountMgr->GetFolderCache(getter_AddRefs(folderCache));
@@ -3438,40 +3437,40 @@ NS_IMETHODIMP nsMsgDBFolder::RecursiveDe
     }
   }
 
   int32_t count = mSubFolders.Count();
   while (count > 0) {
     nsIMsgFolder *child = mSubFolders[0];
 
     child->SetParent(nullptr);
-    status = child->RecursiveDelete(deleteStorage, msgWindow);  // recur
-    if (NS_SUCCEEDED(status))
+    rv = child->RecursiveDelete(deleteStorage, msgWindow);
+    if (NS_SUCCEEDED(rv))
       // unlink it from this child's list
       mSubFolders.RemoveObjectAt(0);
     else {
       // setting parent back if we failed for some reason
       child->SetParent(this);
       break;
     }
 
     count--;
   }
 
   // now delete the disk storage for _this_
-  if (deleteStorage && NS_SUCCEEDED(status)) {
+  if (deleteStorage && NS_SUCCEEDED(rv)) {
     // All delete commands use deleteStorage = true, and local moves use false.
     // IMAP moves use true, leaving this here in the hope that bug 439108
     // works out.
     nsCOMPtr<nsIMsgFolderNotificationService> notifier(
         do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
     if (notifier) notifier->NotifyFolderDeleted(this);
-    status = Delete();
+    rv = DeleteStorage();
   }
-  return status;
+  return rv;
 }
 
 NS_IMETHODIMP nsMsgDBFolder::CreateSubfolder(const nsAString &folderName,
                                              nsIMsgWindow *msgWindow) {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP nsMsgDBFolder::AddSubfolder(const nsAString &name,
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -953,17 +953,17 @@ NS_IMETHODIMP nsImapMailFolder::RemoveSu
   nsresult rv;
   nsCOMPtr<nsIMutableArray> folders(
       do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
   NS_ENSURE_TRUE(folders, rv);
   nsCOMPtr<nsISupports> folderSupport = do_QueryInterface(which, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   folders->AppendElement(folderSupport);
   rv = nsMsgDBFolder::DeleteSubFolders(folders, nullptr);
-  which->Delete();
+  which->DeleteStorage();
   return rv;
 }
 
 NS_IMETHODIMP nsImapMailFolder::CreateStorageIfMissing(
     nsIUrlListener *urlListener) {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMsgFolder> msgParent;
   GetParent(getter_AddRefs(msgParent));
@@ -1392,33 +1392,33 @@ NS_IMETHODIMP nsImapMailFolder::EmptyTra
       }
     }
 
     nsCOMPtr<nsIDBFolderInfo> transferInfo;
     rv = trashFolder->GetDBTransferInfo(getter_AddRefs(transferInfo));
     NS_ENSURE_SUCCESS(rv, rv);
     // Bulk-delete all the messages by deleting the msf file and storage.
     // This is a little kludgy.
-    rv = trashFolder->Delete();
+    rv = trashFolder->DeleteStorage();
     NS_ENSURE_SUCCESS(rv, rv);
     trashFolder->SetDBTransferInfo(transferInfo);
     trashFolder->SetSizeOnDisk(0);
 
     // The trash folder has effectively been deleted.
     nsCOMPtr<nsIMsgFolderNotificationService> notifier(
         do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
     if (notifier) notifier->NotifyFolderDeleted(trashFolder);
 
     return NS_OK;
   }
   return rv;
 }
 
-NS_IMETHODIMP nsImapMailFolder::Delete() {
-  nsresult rv = nsMsgDBFolder::Delete();
+NS_IMETHODIMP nsImapMailFolder::DeleteStorage() {
+  nsresult rv = nsMsgDBFolder::DeleteStorage();
 
   // Should notify nsIMsgFolderListeners about the folder getting deleted?
   return rv;
 }
 
 NS_IMETHODIMP nsImapMailFolder::Rename(const nsAString &newName,
                                        nsIMsgWindow *msgWindow) {
   if (mFlags & nsMsgFolderFlags::Virtual)
@@ -7337,19 +7337,17 @@ nsImapMailFolder::CopyFolder(nsIMsgFolde
       nsCOMPtr<nsIMsgFolder> msgParent;
       srcFolder->GetParent(getter_AddRefs(msgParent));
       srcFolder->SetParent(nullptr);
       if (msgParent) {
         msgParent->PropagateDelete(
             srcFolder, false, msgWindow);  // The files have already been moved,
                                            // so delete storage false
         oldPathFile->Remove(false);        // berkeley mailbox
-        nsCOMPtr<nsIMsgDatabase>
-            srcDB;  // we need to force closed the source db
-        srcFolder->Delete();
+        srcFolder->DeleteStorage();
 
         nsCOMPtr<nsIFile> parentPathFile;
         rv = msgParent->GetFilePath(getter_AddRefs(parentPathFile));
         NS_ENSURE_SUCCESS(rv, rv);
 
         AddDirectorySeparator(parentPathFile);
         nsCOMPtr<nsIDirectoryEnumerator> children;
         parentPathFile->GetDirectoryEntries(getter_AddRefs(children));
--- a/mailnews/imap/src/nsImapMailFolder.h
+++ b/mailnews/imap/src/nsImapMailFolder.h
@@ -226,17 +226,17 @@ class nsImapMailFolder : public nsMsgDBF
   NS_IMETHOD CompactAll(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow,
                         bool aCompactOfflineAlso) override;
   NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow,
                         nsIUrlListener *aListener) override;
   NS_IMETHOD CopyDataToOutputStreamForAppend(
       nsIInputStream *aIStream, int32_t aLength,
       nsIOutputStream *outputStream) override;
   NS_IMETHOD CopyDataDone() override;
-  NS_IMETHOD Delete() override;
+  NS_IMETHOD DeleteStorage() override;
   NS_IMETHOD Rename(const nsAString &newName, nsIMsgWindow *msgWindow) override;
   NS_IMETHOD RenameSubFolders(nsIMsgWindow *msgWindow,
                               nsIMsgFolder *oldFolder) override;
   NS_IMETHOD GetNoSelect(bool *aResult) override;
 
   NS_IMETHOD GetPrettyName(nsAString &prettyName)
       override;  // Override of the base, for top-level mail folder
 
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -512,19 +512,17 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::CopyFol
 
     nsCOMPtr<nsIMsgFolder> msgParent;
     aSrcFolder->GetParent(getter_AddRefs(msgParent));
     aSrcFolder->SetParent(nullptr);
     if (msgParent) {
       // The files have already been moved, so delete storage false
       msgParent->PropagateDelete(aSrcFolder, false, aMsgWindow);
       oldPath->Remove(false);  // berkeley mailbox
-      // We need to force closed the source db
-      nsCOMPtr<nsIMsgDatabase> srcDB;
-      aSrcFolder->Delete();
+      aSrcFolder->DeleteStorage();
 
       nsCOMPtr<nsIFile> parentPath;
       rv = msgParent->GetFilePath(getter_AddRefs(parentPath));
       NS_ENSURE_SUCCESS(rv, rv);
 
       AddDirectorySeparator(parentPath);
       nsCOMPtr<nsIDirectoryEnumerator> children;
       parentPath->GetDirectoryEntries(getter_AddRefs(children));
@@ -540,18 +538,17 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::CopyFol
     // possible.
     if (aIsMoveFolder && NS_FAILED(copyStatus)) {
       nsCOMPtr<nsIMsgFolder> msgParent;
       newMsgFolder->ForceDBClosed();
       newMsgFolder->GetParent(getter_AddRefs(msgParent));
       newMsgFolder->SetParent(nullptr);
       if (msgParent) {
         msgParent->PropagateDelete(newMsgFolder, false, aMsgWindow);
-        newMsgFolder->Delete();
-        newMsgFolder->ForceDBClosed();
+        newMsgFolder->DeleteStorage();
         AddDirectorySeparator(newPath);
         newPath->Remove(true);  // berkeley mailbox
       }
       return NS_ERROR_FAILURE;
     }
   }
   return NS_OK;
 }
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -515,18 +515,17 @@ NS_IMETHODIMP nsMsgMaildirStore::CopyFol
 
     nsCOMPtr<nsIMsgFolder> msgParent;
     aSrcFolder->GetParent(getter_AddRefs(msgParent));
     aSrcFolder->SetParent(nullptr);
     if (msgParent) {
       // The files have already been moved, so delete storage false
       msgParent->PropagateDelete(aSrcFolder, false, aMsgWindow);
       oldPath->Remove(true);
-      nsCOMPtr<nsIMsgDatabase> srcDB;  // we need to force closed the source db
-      aSrcFolder->Delete();
+      aSrcFolder->DeleteStorage();
 
       nsCOMPtr<nsIFile> parentPath;
       rv = msgParent->GetFilePath(getter_AddRefs(parentPath));
       NS_ENSURE_SUCCESS(rv, rv);
 
       AddDirectorySeparator(parentPath);
       nsCOMPtr<nsIDirectoryEnumerator> children;
       parentPath->GetDirectoryEntries(getter_AddRefs(children));
@@ -542,18 +541,17 @@ NS_IMETHODIMP nsMsgMaildirStore::CopyFol
     // possible.
     if (aIsMoveFolder && NS_FAILED(copyStatus)) {
       nsCOMPtr<nsIMsgFolder> msgParent;
       newMsgFolder->ForceDBClosed();
       newMsgFolder->GetParent(getter_AddRefs(msgParent));
       newMsgFolder->SetParent(nullptr);
       if (msgParent) {
         msgParent->PropagateDelete(newMsgFolder, false, aMsgWindow);
-        newMsgFolder->Delete();
-        newMsgFolder->ForceDBClosed();
+        newMsgFolder->DeleteStorage();
         AddDirectorySeparator(newPath);
         newPath->Remove(true);  // berkeley mailbox
       }
       return NS_ERROR_FAILURE;
     }
   }
   return NS_OK;
 }
--- a/mailnews/news/src/nsNewsFolder.cpp
+++ b/mailnews/news/src/nsNewsFolder.cpp
@@ -435,18 +435,18 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateSub
     NotifyItemAdded(child);
     nsCOMPtr<nsIMsgFolderNotificationService> notifier(
         do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID));
     if (notifier) notifier->NotifyFolderAdded(child);
   }
   return rv;
 }
 
-NS_IMETHODIMP nsMsgNewsFolder::Delete() {
-  nsresult rv = nsMsgDBFolder::Delete();
+NS_IMETHODIMP nsMsgNewsFolder::DeleteStorage() {
+  nsresult rv = nsMsgDBFolder::DeleteStorage();
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsINntpIncomingServer> nntpServer;
   rv = GetNntpServer(getter_AddRefs(nntpServer));
   if (NS_FAILED(rv)) return rv;
 
   nsAutoString name;
   rv = GetUnicodeName(name);
--- a/mailnews/news/src/nsNewsFolder.h
+++ b/mailnews/news/src/nsNewsFolder.h
@@ -33,17 +33,17 @@ class nsMsgNewsFolder : public nsMsgDBFo
   NS_IMETHOD GetSubFolders(nsISimpleEnumerator **aResult) override;
 
   NS_IMETHOD GetMessages(nsISimpleEnumerator **result) override;
   NS_IMETHOD UpdateFolder(nsIMsgWindow *aWindow) override;
 
   NS_IMETHOD CreateSubfolder(const nsAString &folderName,
                              nsIMsgWindow *msgWindow) override;
 
-  NS_IMETHOD Delete() override;
+  NS_IMETHOD DeleteStorage() override;
   NS_IMETHOD Rename(const nsAString &newName, nsIMsgWindow *msgWindow) override;
 
   NS_IMETHOD GetAbbreviatedName(nsAString &aAbbreviatedName) override;
 
   NS_IMETHOD GetFolderURL(nsACString &url) override;
 
   NS_IMETHOD GetExpungedBytesCount(int64_t *count);
   NS_IMETHOD GetDeletable(bool *deletable) override;