$OpenBSD: patch-xpcom_io_nsLocalFileUnix_cpp,v 1.1 2021/03/23 13:25:36 landry Exp $

https://bugzilla.mozilla.org/show_bug.cgi?id=1697721

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,23 @@ 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 --
+   * 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);
+  }
 
   return NS_OK;
 }
