Bug 1529596 - part 1 - pull out common NS_ERROR_FILE_ACCESS_DENIED code; r=aklotz
authorNathan Froyd <froydnj@gmail.com>
Thu, 07 Mar 2019 20:40:58 +0000
changeset 524156 db0f22709ad1520a8cc81f9cdc3f8b851c99e08e
parent 524155 622e735af62de5955acf756702db9b81828bc8ee
child 524157 b55a2c1df7bbc041c033747376cf974e545be26e
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1529596
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1529596 - part 1 - pull out common NS_ERROR_FILE_ACCESS_DENIED code; r=aklotz This condition logically belongs before we try creating anything. Differential Revision: https://phabricator.services.mozilla.com/D22359
xpcom/io/nsLocalFileWin.cpp
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -1199,48 +1199,43 @@ nsLocalFile::Create(uint32_t aType, uint
         directoryCreateError = rv;
       }
       *slash = L'\\';
       ++slash;
       slash = wcschr(slash, L'\\');
     }
   }
 
+  // If our last CreateDirectory failed due to access, return that.
+  if (NS_ERROR_FILE_ACCESS_DENIED == directoryCreateError) {
+    return directoryCreateError;
+  }
+
   if (aType == NORMAL_FILE_TYPE) {
     PRFileDesc* file;
     rv = OpenFile(mResolvedPath,
                   PR_RDONLY | PR_CREATE_FILE | PR_APPEND | PR_EXCL, aAttributes,
                   false, &file);
     if (file) {
       PR_Close(file);
     }
 
     if (rv == NS_ERROR_FILE_ACCESS_DENIED) {
       // need to return already-exists for directories (bug 452217)
       bool isdir;
       if (NS_SUCCEEDED(IsDirectory(&isdir)) && isdir) {
         rv = NS_ERROR_FILE_ALREADY_EXISTS;
       }
-    } else if (NS_ERROR_FILE_NOT_FOUND == rv &&
-               NS_ERROR_FILE_ACCESS_DENIED == directoryCreateError) {
-      // If a previous CreateDirectory failed due to access, return that.
-      return NS_ERROR_FILE_ACCESS_DENIED;
     }
     return rv;
   }
 
   if (aType == DIRECTORY_TYPE) {
     if (!::CreateDirectoryW(mResolvedPath.get(), nullptr)) {
-      rv = ConvertWinError(GetLastError());
-      if (NS_ERROR_FILE_NOT_FOUND == rv &&
-          NS_ERROR_FILE_ACCESS_DENIED == directoryCreateError) {
-        // If a previous CreateDirectory failed due to access, return that.
-        return NS_ERROR_FILE_ACCESS_DENIED;
-      }
-      return rv;
+      return ConvertWinError(GetLastError());
     }
     return NS_OK;
   }
 
   return NS_ERROR_FILE_UNKNOWN_TYPE;
 }
 
 NS_IMETHODIMP