Bug 1496727 - use GetNextFile when iterating nsIDirectoryEnumerator in C-C. r=jorgk
authoraceman <acelists@atlas.sk>
Fri, 05 Oct 2018 18:24:00 +0200
changeset 33314 a87795783553295e890fdf7bacb0cb92cd24dcb8
parent 33313 f34a77fd94161f3c02a35d31a3c4e6f24450c6ca
child 33315 9528e42be304dc8092836f4e3897b6678b79be31
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1496727
Bug 1496727 - use GetNextFile when iterating nsIDirectoryEnumerator in C-C. r=jorgk
mail/components/migration/src/nsNetscapeProfileMigratorBase.cpp
mail/components/search/nsMailWinSearchHelper.cpp
mailnews/base/src/nsSpamSettings.cpp
mailnews/compose/src/nsMsgAttachmentHandler.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/import/applemail/src/nsAppleMailImport.cpp
mailnews/import/becky/src/nsBeckyAddressBooks.cpp
mailnews/import/becky/src/nsBeckyMail.cpp
mailnews/import/becky/src/nsBeckyUtils.cpp
mailnews/import/winlivemail/nsWMUtils.cpp
mailnews/local/src/nsMsgBrkMBoxStore.cpp
mailnews/local/src/nsMsgMaildirStore.cpp
suite/components/profile/nsNetscapeProfileMigratorBase.cpp
--- a/mail/components/migration/src/nsNetscapeProfileMigratorBase.cpp
+++ b/mail/components/migration/src/nsNetscapeProfileMigratorBase.cpp
@@ -230,41 +230,35 @@ nsNetscapeProfileMigratorBase::GetSignon
 nsresult
 nsNetscapeProfileMigratorBase::LocateSignonsFile(nsACString& aResult)
 {
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   nsresult rv = mSourceProfile->GetDirectoryEntries(getter_AddRefs(entries));
   if (NS_FAILED(rv)) return rv;
 
   nsAutoCString fileName;
-  do {
-    bool hasMore = false;
-    rv = entries->HasMoreElements(&hasMore);
-    if (NS_FAILED(rv) || !hasMore) break;
-
-    nsCOMPtr<nsISupports> supp;
-    rv = entries->GetNext(getter_AddRefs(supp));
+  bool hasMore = false;
+  while (NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) {
+    nsCOMPtr<nsIFile> currFile;
+    rv = entries->GetNextFile(getter_AddRefs(currFile));
     if (NS_FAILED(rv)) break;
 
-    nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp));
-
     nsCOMPtr<nsIURI> uri;
     rv = NS_NewFileURI(getter_AddRefs(uri), currFile);
     if (NS_FAILED(rv)) break;
     nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
 
     nsAutoCString extn;
     url->GetFileExtension(extn);
 
     if (extn.EqualsIgnoreCase("s")) {
       url->GetFileName(fileName);
       break;
     }
   }
-  while (1);
 
   aResult = fileName;
 
   return NS_OK;
 }
 
 // helper function, copies the contents of srcDir into destDir.
 // destDir will be created if it doesn't exist.
@@ -279,31 +273,25 @@ nsresult nsNetscapeProfileMigratorBase::
   if (!isDir) return NS_ERROR_INVALID_ARG;
 
   bool exists;
   rv = destDir->Exists(&exists);
   if (NS_SUCCEEDED(rv) && !exists)
     rv = destDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
   if (NS_FAILED(rv)) return rv;
 
-  bool hasMore = false;
   nsCOMPtr<nsIDirectoryEnumerator> dirIterator;
   rv = srcDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
   if (NS_FAILED(rv)) return rv;
 
-  rv = dirIterator->HasMoreElements(&hasMore);
-  if (NS_FAILED(rv)) return rv;
-
-  nsCOMPtr<nsIFile> dirEntry;
-
-  while (hasMore)
+  bool hasMore = false;
+  while (NS_SUCCEEDED(dirIterator->HasMoreElements(&hasMore)) && hasMore)
   {
-    nsCOMPtr<nsISupports> supports;
-    rv = dirIterator->GetNext(getter_AddRefs(supports));
-    dirEntry = do_QueryInterface(supports);
+    nsCOMPtr<nsIFile> dirEntry;
+    rv = dirIterator->GetNextFile(getter_AddRefs(dirEntry));
     if (NS_SUCCEEDED(rv) && dirEntry)
     {
       rv = dirEntry->IsDirectory(&isDir);
       if (NS_SUCCEEDED(rv))
       {
         if (isDir)
         {
           nsCOMPtr<nsIFile> newChild;
@@ -326,18 +314,16 @@ nsresult nsNetscapeProfileMigratorBase::
           fileTransactionEntry fileEntry;
           fileEntry.srcFile = dirEntry;
           fileEntry.destFile = destDir;
 
           mFileCopyTransactions.AppendElement(fileEntry);
         }
       }
     }
-    rv = dirIterator->HasMoreElements(&hasMore);
-    if (NS_FAILED(rv)) return rv;
   }
 
   return rv;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // nsITimerCallback
 
--- a/mail/components/search/nsMailWinSearchHelper.cpp
+++ b/mail/components/search/nsMailWinSearchHelper.cpp
@@ -166,23 +166,21 @@ NS_IMETHODIMP nsMailWinSearchHelper::Set
   rv = aFile->IsDirectory(&isDirectory);
   NS_ENSURE_SUCCESS(rv, rv);
   if (aRecurse && isDirectory)
   {
     nsCOMPtr<nsIDirectoryEnumerator> children;
     rv = aFile->GetDirectoryEntries(getter_AddRefs(children));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    bool hasMore;
-    while (NS_SUCCEEDED(rv) && NS_SUCCEEDED(children->HasMoreElements(&hasMore)) && hasMore)
+    bool hasMore = false;
+    while (NS_SUCCEEDED(children->HasMoreElements(&hasMore)) && hasMore)
     {
-      nsCOMPtr<nsISupports> supports;
-      rv = children->GetNext(getter_AddRefs(supports));
-      NS_ENSURE_SUCCESS(rv, rv);
-      nsCOMPtr<nsIFile> childFile = do_QueryInterface(supports, &rv);
+      nsCOMPtr<nsIFile> childFile;
+      rv = children->GetNextFile(getter_AddRefs(childFile));
       NS_ENSURE_SUCCESS(rv, rv);
       rv = SetFANCIBit(childFile, aBit, aRecurse);
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP nsMailWinSearchHelper::GetIsFileAssociationSet(bool *aResult)
--- a/mailnews/base/src/nsSpamSettings.cpp
+++ b/mailnews/base/src/nsSpamSettings.cpp
@@ -23,17 +23,16 @@
 #include "mozilla/Services.h"
 #include "mozilla/mailnews/MimeHeaderParser.h"
 #include "nsIArray.h"
 #include "nsArrayUtils.h"
 #include "nsMailDirServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsISimpleEnumerator.h"
-#include "nsIDirectoryEnumerator.h"
 #include "nsAbBaseCID.h"
 #include "nsIAbManager.h"
 #include "nsIMsgAccountManager.h"
 #include "nsMsgBaseCID.h"
 
 using namespace mozilla::mailnews;
 
 nsSpamSettings::nsSpamSettings()
--- a/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -27,17 +27,16 @@
 #include "nsIDirectoryEnumerator.h"
 #include "nsNetCID.h"
 #include "nsIMimeStreamConverter.h"
 #include "nsMsgMimeCID.h"
 #include "nsNetUtil.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsComposeStrings.h"
 #include "nsIZipWriter.h"
-#include "nsIDirectoryEnumerator.h"
 #include "mozilla/Services.h"
 #include "mozilla/mailnews/MimeEncoder.h"
 #include "nsIPrincipal.h"
 #include "nsIURIMutator.h"
 
 ///////////////////////////////////////////////////////////////////////////
 // Mac Specific Attachment Handling for AppleDouble Encoded Files
 ///////////////////////////////////////////////////////////////////////////
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -1,9 +1,10 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode:
+ C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "msgCore.h"
 #include "prmem.h"
 #include "nsMsgImapCID.h"
 #include "nsImapMailFolder.h"
@@ -66,16 +67,17 @@
 #include "nsMsgMessageFlags.h"
 #include "nsISpamSettings.h"
 #include <time.h>
 #include "nsIMsgMailNewsUrl.h"
 #include "nsEmbedCID.h"
 #include "nsIMsgComposeService.h"
 #include "nsMsgCompCID.h"
 #include "nsDirectoryServiceDefs.h"
+#include "nsIDirectoryEnumerator.h"
 #include "nsIMsgIdentity.h"
 #include "nsIMsgFolderNotificationService.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsIExternalProtocolService.h"
 #include "nsCExternalHandlerService.h"
 #include "prprf.h"
 #include "nsIMutableArray.h"
 #include "nsArrayUtils.h"
@@ -117,31 +119,26 @@ nsresult RecursiveCopy(nsIFile* srcDir, 
   if (!isDir) return NS_ERROR_INVALID_ARG;
 
   bool exists;
   rv = destDir->Exists(&exists);
   if (NS_SUCCEEDED(rv) && !exists)
     rv = destDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
   if (NS_FAILED(rv)) return rv;
 
-  bool hasMore = false;
+
   nsCOMPtr<nsIDirectoryEnumerator> dirIterator;
   rv = srcDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
   if (NS_FAILED(rv)) return rv;
 
-  rv = dirIterator->HasMoreElements(&hasMore);
-  if (NS_FAILED(rv)) return rv;
-
-  nsCOMPtr<nsIFile> dirEntry;
-
-  while (hasMore)
-  {
-    nsCOMPtr<nsISupports> supports;
-    rv = dirIterator->GetNext(getter_AddRefs(supports));
-    dirEntry = do_QueryInterface(supports);
+  bool hasMore = false;
+  while (NS_SUCCEEDED(dirIterator->HasMoreElements(&hasMore)) && hasMore)
+  {
+    nsCOMPtr<nsIFile> dirEntry;
+    rv = dirIterator->GetNextFile(getter_AddRefs(dirEntry));
     if (NS_SUCCEEDED(rv) && dirEntry)
     {
       rv = dirEntry->IsDirectory(&isDir);
       if (NS_SUCCEEDED(rv))
       {
         if (isDir)
         {
           nsCOMPtr<nsIFile> newChild;
@@ -157,18 +154,16 @@ nsresult RecursiveCopy(nsIFile* srcDir, 
             rv = RecursiveCopy(dirEntry, newChild);
           }
         }
         else
           rv = dirEntry->CopyTo(destDir, EmptyString());
       }
 
     }
-    rv = dirIterator->HasMoreElements(&hasMore);
-    if (NS_FAILED(rv)) return rv;
   }
 
   return rv;
 }
 
 nsImapMailFolder::nsImapMailFolder() :
     m_initialized(false),m_haveDiscoveredAllFolders(false),
     m_curMsgUid(0), m_nextMessageByteLength(0),
@@ -425,23 +420,21 @@ nsresult nsImapMailFolder::CreateSubFold
   rv = GetServer(getter_AddRefs(server));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDirectoryEnumerator> children;
   rv = path->GetDirectoryEntries(getter_AddRefs(children));
   bool more = false;
   if (children)
     children->HasMoreElements(&more);
-  nsCOMPtr<nsIFile> currentFolderPath;
 
   while (more)
   {
-    nsCOMPtr<nsISupports> supports;
-    rv = children->GetNext(getter_AddRefs(supports));
-    currentFolderPath = do_QueryInterface(supports);
+    nsCOMPtr<nsIFile> currentFolderPath;
+    rv = children->GetNextFile(getter_AddRefs(currentFolderPath));
     if (NS_FAILED(rv) || !currentFolderPath)
       break;
     rv = children->HasMoreElements(&more);
     if (NS_FAILED(rv)) return rv;
 
     currentFolderPath->GetLeafName(currentFolderNameStr);
     if (nsShouldIgnoreFile(currentFolderNameStr))
       continue;
--- a/mailnews/import/applemail/src/nsAppleMailImport.cpp
+++ b/mailnews/import/applemail/src/nsAppleMailImport.cpp
@@ -231,28 +231,21 @@ void nsAppleMailImportMail::FindAccountM
 {
   nsCOMPtr<nsIDirectoryEnumerator> directoryEnumerator;
   nsresult rv = aRoot->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
   if (NS_FAILED(rv))
     return;
 
   bool hasMore = false;
   while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) {
-
     // get the next file entry
     nsCOMPtr<nsIFile> currentEntry;
-    {
-      nsCOMPtr<nsISupports> rawSupports;
-      directoryEnumerator->GetNext(getter_AddRefs(rawSupports));
-      if (!rawSupports)
-        continue;
-      currentEntry = do_QueryInterface(rawSupports);
-      if (!currentEntry)
-        continue;
-    }
+    directoryEnumerator->GetNextFile(getter_AddRefs(currentEntry));
+    if (!currentEntry)
+      continue;
 
     // make sure it's a directory
     bool isDirectory = false;
     currentEntry->IsDirectory(&isDirectory);
 
     if (isDirectory) {
       // now let's see if it's an account folder. if so, we want to traverse it for .mbox children
       nsAutoString folderName;
@@ -330,22 +323,18 @@ nsresult nsAppleMailImportMail::AddMboxD
 
       // count the number of messages in this folder. it sucks that we have to iterate through the folder
       // but XPCOM doesn't give us any way to just get the file count, unfortunately. :-(
       nsCOMPtr<nsIDirectoryEnumerator> dirEnumerator;
       messagesFolder->GetDirectoryEntries(getter_AddRefs(dirEnumerator));
       if (dirEnumerator) {
         bool hasMore = false;
         while (NS_SUCCEEDED(dirEnumerator->HasMoreElements(&hasMore)) && hasMore) {
-          nsCOMPtr<nsISupports> rawSupports;
-          dirEnumerator->GetNext(getter_AddRefs(rawSupports));
-          if (!rawSupports)
-            continue;
-
-          nsCOMPtr<nsIFile> file(do_QueryInterface(rawSupports));
+          nsCOMPtr<nsIFile> file;
+          dirEnumerator->GetNextFile(getter_AddRefs(file));
           if (file) {
             bool isFile = false;
             file->IsFile(&isFile);
             if (isFile)
               numMessages++;
           }
         }
       }
@@ -396,28 +385,21 @@ nsresult nsAppleMailImportMail::FindMbox
   // iterate through the folder contents
   nsCOMPtr<nsIDirectoryEnumerator> directoryEnumerator;
   nsresult rv = aFolder->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
   if (NS_FAILED(rv) || !directoryEnumerator)
     return rv;
 
   bool hasMore = false;
   while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) {
-
     // get the next file entry
     nsCOMPtr<nsIFile> currentEntry;
-    {
-      nsCOMPtr<nsISupports> rawSupports;
-      directoryEnumerator->GetNext(getter_AddRefs(rawSupports));
-      if (!rawSupports)
-        continue;
-      currentEntry = do_QueryInterface(rawSupports);
-      if (!currentEntry)
-        continue;
-    }
+    directoryEnumerator->GetNextFile(getter_AddRefs(currentEntry));
+    if (!currentEntry)
+      continue;
 
     // we only care about directories...
     if (NS_FAILED(currentEntry->IsDirectory(&isDir)) || !isDir)
       continue;
 
     // now find out if this is a .mbox dir
     nsAutoString currentFolderName;
     if (NS_SUCCEEDED(currentEntry->GetLeafName(currentFolderName)) &&
@@ -532,25 +514,19 @@ nsAppleMailImportMail::ImportMailbox(nsI
     }
 
     bool hasMore = false;
     nsCOMPtr<nsIOutputStream> outStream;
 
     while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) {
       // get the next file entry
       nsCOMPtr<nsIFile> currentEntry;
-      {
-        nsCOMPtr<nsISupports> rawSupports;
-        directoryEnumerator->GetNext(getter_AddRefs(rawSupports));
-        if (!rawSupports)
-          continue;
-        currentEntry = do_QueryInterface(rawSupports);
-        if (!currentEntry)
-          continue;
-      }
+      directoryEnumerator->GetNextFile(getter_AddRefs(currentEntry));
+      if (!currentEntry)
+        continue;
 
       // make sure it's an .emlx file
       bool isFile = false;
       currentEntry->IsFile(&isFile);
       if (!isFile)
         continue;
 
       nsAutoString leafName;
--- a/mailnews/import/becky/src/nsBeckyAddressBooks.cpp
+++ b/mailnews/import/becky/src/nsBeckyAddressBooks.cpp
@@ -156,22 +156,19 @@ nsBeckyAddressBooks::HasAddressBookFile(
   if (NS_FAILED(rv) || !isDirectory)
     return false;
 
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
   NS_ENSURE_SUCCESS(rv, false);
 
   bool more;
-  nsCOMPtr<nsISupports> entry;
   while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
-    rv = entries->GetNext(getter_AddRefs(entry));
-    NS_ENSURE_SUCCESS(rv, false);
-
-    nsCOMPtr<nsIFile> file = do_QueryInterface(entry, &rv);
+    nsCOMPtr<nsIFile> file;
+    rv = entries->GetNextFile(getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, false);
     if (IsAddressBookFile(file))
       return true;
   }
 
   return false;
 }
 
@@ -188,22 +185,19 @@ nsBeckyAddressBooks::CountAddressBookSiz
     return 0;
 
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
   NS_ENSURE_SUCCESS(rv, 0);
 
   uint32_t total = 0;
   bool more;
-  nsCOMPtr<nsISupports> entry;
   while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
-    rv = entries->GetNext(getter_AddRefs(entry));
-    NS_ENSURE_SUCCESS(rv, 0);
-
-    nsCOMPtr<nsIFile> file = do_QueryInterface(entry, &rv);
+    nsCOMPtr<nsIFile> file;
+    rv = entries->GetNextFile(getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, 0);
 
     int64_t size;
     file->GetFileSize(&size);
     if (total + size > std::numeric_limits<uint32_t>::max())
       return std::numeric_limits<uint32_t>::max();
 
     total += static_cast<uint32_t>(size);
@@ -244,22 +238,19 @@ nsBeckyAddressBooks::CollectAddressBooks
   nsresult rv = AppendAddressBookDescriptor(aTarget, aCollected);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   rv = aTarget->GetDirectoryEntries(getter_AddRefs(entries));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool more;
-  nsCOMPtr<nsISupports> entry;
   while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
-    rv = entries->GetNext(getter_AddRefs(entry));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIFile> file = do_QueryInterface(entry, &rv);
+    nsCOMPtr<nsIFile> file;
+    rv = entries->GetNextFile(getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, rv);
 
     bool isDirectory = false;
     rv = file->IsDirectory(&isDirectory);
     if (NS_SUCCEEDED(rv) && isDirectory)
       rv = CollectAddressBooks(file, aCollected);
     NS_ENSURE_SUCCESS(rv, rv);
   }
@@ -318,23 +309,20 @@ nsBeckyAddressBooks::ImportAddressBook(n
   nsresult rv = aSource->GetAbFile(getter_AddRefs(file));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   rv = file->GetDirectoryEntries(getter_AddRefs(entries));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool more;
-  nsCOMPtr<nsISupports> entry;
   nsAutoString error;
   while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
-    rv = entries->GetNext(getter_AddRefs(entry));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIFile> file = do_QueryInterface(entry, &rv);
+    nsCOMPtr<nsIFile> file;
+    rv = entries->GetNextFile(getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!IsAddressBookFile(file))
       continue;
 
     bool aborted = false;
     nsAutoString name;
     aSource->GetPreferredName(name);
--- a/mailnews/import/becky/src/nsBeckyMail.cpp
+++ b/mailnews/import/becky/src/nsBeckyMail.cpp
@@ -207,21 +207,18 @@ nsBeckyMail::CollectMailboxesInDirectory
   }
 
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   rv = aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool more;
   while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
-    nsCOMPtr<nsISupports> entry;
-    rv = entries->GetNext(getter_AddRefs(entry));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIFile> file = do_QueryInterface(entry, &rv);
+    nsCOMPtr<nsIFile> file;
+    rv = entries->GetNextFile(getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoString name;
     rv = file->GetLeafName(name);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (StringEndsWith(name, NS_LITERAL_STRING(".bmf"))) {
       AppendMailboxDescriptor(file, mailboxName, aDepth, aCollected);
--- a/mailnews/import/becky/src/nsBeckyUtils.cpp
+++ b/mailnews/import/becky/src/nsBeckyUtils.cpp
@@ -81,21 +81,19 @@ nsBeckyUtils::FindUserDirectoryOnWindows
   if (!isDirectory)
     return NS_ERROR_FILE_NOT_FOUND;
 
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   rv = directory->GetDirectoryEntries(getter_AddRefs(entries));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool more;
-  nsCOMPtr<nsISupports> entry;
   while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
-    rv = entries->GetNext(getter_AddRefs(entry));
-
-    nsCOMPtr<nsIFile> file = do_QueryInterface(entry, &rv);
+    nsCOMPtr<nsIFile> file;
+    rv = entries->GetNextFile(getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, rv);
 
     bool isDirectory = false;
     rv = file->IsDirectory(&isDirectory);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (isDirectory) {
       file.forget(aLocation);
--- a/mailnews/import/winlivemail/nsWMUtils.cpp
+++ b/mailnews/import/winlivemail/nsWMUtils.cpp
@@ -99,21 +99,18 @@ nsWMUtils::GetOEAccountFilesInFolder(nsI
 {
   nsCOMPtr<nsIDirectoryEnumerator> entries;
   nsresult rv = aFolder->GetDirectoryEntries(getter_AddRefs(entries));
   if (NS_FAILED(rv) || !entries)
     return NS_ERROR_FAILURE;
 
   bool hasMore;
   while (NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) {
-    nsCOMPtr<nsISupports> supports;
-    rv = entries->GetNext(getter_AddRefs(supports));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIFile> file = do_QueryInterface(supports);
+    nsCOMPtr<nsIFile> file;
+    rv = entries->GetNextFile(getter_AddRefs(file));
     NS_ENSURE_SUCCESS(rv, rv);
 
     bool isDirectory;
     rv = file->IsDirectory(&isDirectory);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (isDirectory) {
       GetOEAccountFilesInFolder(file, aFileArray);
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -10,16 +10,17 @@
 #include "prlog.h"
 #include "msgCore.h"
 #include "nsMsgBrkMBoxStore.h"
 #include "nsIMsgFolder.h"
 #include "nsMsgFolderFlags.h"
 #include "nsIMsgLocalMailFolder.h"
 #include "nsCOMArray.h"
 #include "nsIFile.h"
+#include "nsIDirectoryEnumerator.h"
 #include "nsIMsgHdr.h"
 #include "nsNetUtil.h"
 #include "nsIMsgDatabase.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsMsgUtils.h"
 #include "nsMsgDBCID.h"
 #include "nsIDBFolderInfo.h"
 #include "nsIArray.h"
@@ -1034,19 +1035,18 @@ nsMsgBrkMBoxStore::AddSubFolders(nsIMsgF
   nsCOMPtr<nsIDirectoryEnumerator> directoryEnumerator;
   rv = path->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMore;
   while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) &&
          hasMore)
   {
-    nsCOMPtr<nsISupports> aSupport;
-    directoryEnumerator->GetNext(getter_AddRefs(aSupport));
-    nsCOMPtr<nsIFile> currentFile(do_QueryInterface(aSupport, &rv));
+    nsCOMPtr<nsIFile> currentFile;
+    directoryEnumerator->GetNextFile(getter_AddRefs(currentFile));
     if (currentFile)
       currentDirEntries.AppendObject(currentFile);
   }
 
   // add the folders
   int32_t count = currentDirEntries.Count();
   for (int32_t i = 0; i < count; ++i)
   {
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -59,20 +59,19 @@ nsresult nsMsgMaildirStore::AddSubFolder
   nsCOMPtr<nsIDirectoryEnumerator> directoryEnumerator;
   nsresult rv = path->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMore;
   while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) &&
          hasMore)
   {
-    nsCOMPtr<nsISupports> aSupport;
-    directoryEnumerator->GetNext(getter_AddRefs(aSupport));
-    nsCOMPtr<nsIFile> currentFile(do_QueryInterface(aSupport, &rv));
-    if (currentFile) {
+    nsCOMPtr<nsIFile> currentFile;
+    rv = directoryEnumerator->GetNextFile(getter_AddRefs(currentFile));
+    if (NS_SUCCEEDED(rv) && currentFile) {
       nsAutoString leafName;
       currentFile->GetLeafName(leafName);
       bool isDirectory = false;
       currentFile->IsDirectory(&isDirectory);
       // Make sure this really is a mail folder dir (i.e., a directory that
       // contains cur and tmp sub-dirs, and not a .sbd or .mozmsgs dir).
       if (isDirectory && !nsShouldIgnoreFile(leafName))
         currentDirEntries.AppendObject(currentFile);
@@ -1254,20 +1253,18 @@ void MaildirStoreParser::TimerCallback(n
         (void)url->SetSpecInternal(uriSpec);
         parser->m_listener->OnStopRunningUrl(url, NS_OK);
       }
     }
     // Parsing complete and timer cancelled, so we release the parser object.
     delete parser;
     return;
   }
-  nsCOMPtr<nsISupports> aSupport;
-  parser->m_directoryEnumerator->GetNext(getter_AddRefs(aSupport));
-  nsresult rv;
-  nsCOMPtr<nsIFile> currentFile(do_QueryInterface(aSupport, &rv));
+  nsCOMPtr<nsIFile> currentFile;
+  nsresult rv = parser->m_directoryEnumerator->GetNextFile(getter_AddRefs(currentFile));
   NS_ENSURE_SUCCESS_VOID(rv);
   parser->ParseNextMessage(currentFile);
   // ### TODO - what if this fails?
 }
 
 nsresult MaildirStoreParser::StartTimer()
 {
   nsresult rv;
--- a/suite/components/profile/nsNetscapeProfileMigratorBase.cpp
+++ b/suite/components/profile/nsNetscapeProfileMigratorBase.cpp
@@ -457,33 +457,26 @@ nsNetscapeProfileMigratorBase::Recursive
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!isDir)
     return NS_ERROR_INVALID_ARG;
 
   rv = destDir->Exists(&exists);
   if (NS_SUCCEEDED(rv) && !exists)
     rv = destDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
-
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDirectoryEnumerator> dirIterator;
   rv = srcDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasMore = false;
-  rv = dirIterator->HasMoreElements(&hasMore);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIFile> dirEntry;
-
-  while (hasMore) {
-    nsCOMPtr<nsISupports> supports;
-    rv = dirIterator->GetNext(getter_AddRefs(supports));
-    dirEntry = do_QueryInterface(supports);
+  while (NS_SUCCEEDED(dirIterator->HasMoreElements(&hasMore)) && hasMore) {
+    nsCOMPtr<nsIFile> dirEntry;
+    rv = dirIterator->GetNextFile(getter_AddRefs(dirEntry));
     if (NS_SUCCEEDED(rv) && dirEntry) {
       rv = dirEntry->IsDirectory(&isDir);
       if (NS_SUCCEEDED(rv)) {
         if (isDir) {
           nsCOMPtr<nsIFile> newChild;
           rv = destDir->Clone(getter_AddRefs(newChild));
           if (NS_SUCCEEDED(rv)) {
             nsAutoString leafName;
@@ -505,19 +498,16 @@ nsNetscapeProfileMigratorBase::Recursive
 
           fileEntry.srcFile = dirEntry;
           fileEntry.destFile = destDir;
 
           mFileCopyTransactions.AppendElement(fileEntry);
         }
       }
     }
-    rv = dirIterator->HasMoreElements(&hasMore);
-    if (NS_FAILED(rv))
-      return rv;
   }
 
   return rv;
 }
 
 void
 nsNetscapeProfileMigratorBase::ReadBranch(const char * branchName,
                                           nsIPrefService* aPrefService,