> im not 100% sure at all, but *maybe* the method creating the dir
> hierarchy is
> https://searchfox.org/mozilla-central/source/xpcom/io/nsLocalFileUnix.cpp#360 
> .

You were right. I've created a bug on Bugzilla at
https://bugzilla.mozilla.org/show_bug.cgi?id=1697721 about this issue.

If you are interested, a patch-compatible version is below.


Index: xpcom/io/nsLocalFileUnix.cpp
--- xpcom/io/nsLocalFileUnix.cpp.orig
+++ xpcom/io/nsLocalFileUnix.cpp
@@ -365,6 +365,8 @@ nsLocalFile::CreateAllAncestors(uint32_t aPermissions)
   // <jband> I promise to play nice
   char* buffer = mPath.BeginWriting();
   char* slashp = buffer;
+  int mkdir_result = 0;
+  int mkdir_errno;

 #ifdef DEBUG_NSIFILE
   fprintf(stderr, "nsIFile: before: %s\n", buffer);
@@ -393,9 +395,9 @@ nsLocalFile::CreateAllAncestors(uint32_t aPermissions)
 #ifdef DEBUG_NSIFILE
     fprintf(stderr, "nsIFile: mkdir(\"%s\")\n", buffer);
 #endif
-    int mkdir_result = mkdir(buffer, aPermissions);
-    int mkdir_errno = errno;
+    mkdir_result = mkdir(buffer, aPermissions);
     if (mkdir_result == -1) {
+      mkdir_errno = errno;
       /*
        * Always set |errno| to EEXIST if the dir already exists
        * (we have to do this here since the errno value is not consistent
@@ -408,23 +410,22 @@ nsLocalFile::CreateAllAncestors(uint32_t aPermissions)
       }
     }

-    /* Put the / back before we (maybe) return */
+    /* Put the / back */
     *slashp = '/';
-
-    /*
-     * We could get EEXIST for an existing file -- not directory --
-     * with the name of one of our ancestors, but that's OK: we'll get
-     * ENOTDIR when we try to make the next component in the path,
-     * either here on back in Create, and error out appropriately.
-     */
-    if (mkdir_result == -1 && mkdir_errno != EEXIST) {
-      return nsresultForErrno(mkdir_errno);
-    }
   }

 #ifdef DEBUG_NSIFILE
   fprintf(stderr, "nsIFile: after: %s\n", buffer);
 #endif
+
+  /*
+   * We could get EEXIST for an existing file -- not directory --
+   * but that's OK: we'll get ENOTDIR when we try to make the final
+   * component of the path back in Create and error out appropriately.
+   */
+  if (mkdir_result == -1 && mkdir_errno != EEXIST) {
+    return NS_ERROR_FAILURE;
+  }

   return NS_OK;
 }

Reply via email to