Bug 986080 - Return empty array if getting directory entries fails. r=Mossop
authorIrving Reid <irving@mozilla.com>
Thu, 20 Mar 2014 14:43:56 -0400
changeset 174762 29d33fe0614c16d5aa4b871e31fa2fd4d56e9657
parent 174761 2ff265d0eb77b641497e7d44a00b320ec1432e72
child 174763 675945ee26093fefb0bdd44a6e2c30a8050a7e04
push id5835
push userryanvm@gmail.com
push dateFri, 21 Mar 2014 17:44:18 +0000
treeherderfx-team@675945ee2609 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs986080
milestone31.0a1
Bug 986080 - Return empty array if getting directory entries fails. r=Mossop
toolkit/mozapps/extensions/internal/XPIProvider.jsm
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1316,17 +1316,17 @@ function recursiveLastModifiedTime(aFile
 
 /**
  * Gets a snapshot of directory entries.
  *
  * @param  aDir
  *         Directory to look at
  * @param  aSortEntries
  *         True to sort entries by filename
- * @return An array of nsIFile, or null if aDir is not a readable directory
+ * @return An array of nsIFile, or an empty array if aDir is not a readable directory
  */
 function getDirectoryEntries(aDir, aSortEntries) {
   let dirEnum;
   try {
     dirEnum = aDir.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
     let entries = [];
     while (dirEnum.hasMoreElements())
       entries.push(dirEnum.nextFile);
@@ -1335,20 +1335,23 @@ function getDirectoryEntries(aDir, aSort
       entries.sort(function sortDirEntries(a, b) {
         return a.path > b.path ? -1 : 1;
       });
     }
 
     return entries
   }
   catch (e) {
-    return null;
+    logger.warn("Can't iterate directory " + aDir.path, e);
+    return [];
   }
   finally {
-    dirEnum.close();
+    if (dirEnum) {
+      dirEnum.close();
+    }
   }
 }
 
 /**
  * A helpful wrapper around the prefs service that allows for default values
  * when requested values aren't set.
  */
 var Prefs = {