Bug 808126 - Part 2: Work around bug in OS.File.exists(); r=rnewman
authorGregory Szorc <gps@mozilla.com>
Sun, 06 Jan 2013 23:03:42 -0800
changeset 117783 634951119fef1c6d650f6eaa462ad9368ea54d4a
parent 117782 d3c914f579dd1b4d83ac6078a27a2b50756d1374
child 117784 9e11714fcba22079e5aa9adae13cb5b7f1481d25
push id740
push usergszorc@mozilla.com
push dateMon, 07 Jan 2013 07:03:55 +0000
treeherderservices-central@634951119fef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs808126
milestone20.0a1
Bug 808126 - Part 2: Work around bug in OS.File.exists(); r=rnewman
services/healthreport/providers.jsm
--- a/services/healthreport/providers.jsm
+++ b/services/healthreport/providers.jsm
@@ -959,21 +959,30 @@ CrashDirectoryService.prototype = Object
     return this._getDirectoryEntries(this._submittedDir,
                                      this.RE_SUBMITTED_FILENAME);
   },
 
   _getDirectoryEntries: function (path, re) {
     let files = {};
 
     return Task.spawn(function iterateDirectory() {
-      if (!(yield OS.File.exists(path))) {
-        throw new Task.Result(files);
-      }
+      // The behavior with non-existent dirs is weird.
+      // OS.File.exists() doesn't properly detect directories it appears.
+      // So, we can't use OS.File.exists() to short-circuit operation.
+      //
+      // At the time this was written, the DirectoryIterator constructor did
+      // not throw if the directory did not exist. However, on first .next(),
+      // it will throw. This exception will be uncaught and will cause the
+      // entire Task to be rejected. This is arguably acceptable. Unfortunately,
+      // the exception emitted is not part of OS.File's public API, so we can't
+      // catch it. Sadness.
+      //
+      // We should revisit this behavior once OS.File behaves more sanely.
+      let iterator = new OS.File.DirectoryIterator(path);
 
-      let iterator = new OS.File.DirectoryIterator(path);
       try {
         while (true) {
           let entry;
           try {
             entry = yield iterator.next();
           } catch (ex if ex == StopIteration) {
             break;
           }