Bug 1529596 - part 3 - avoid directory creation in the common case; r=aklotz
authorNathan Froyd <froydnj@gmail.com>
Thu, 07 Mar 2019 20:44:00 +0000
changeset 524158 de92c0248a0b0ecbf0ad104650305a31985fa6ff
parent 524157 b55a2c1df7bbc041c033747376cf974e545be26e
child 524159 6391f42aaa6d59c51c81c2da0681243a463a8012
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 3 - avoid directory creation in the common case; r=aklotz This change sets up nsLocalFileWin to mirror the behavior of nsLocalFileUnix, which is all-around more reasonable than the behavior nsLocalFileWin had before. We also, in passing, fix up some unnecessary error-handling code at the end of Create(). Depends on D22360 Differential Revision: https://phabricator.services.mozilla.com/D22361
xpcom/io/nsLocalFileWin.cpp
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -1168,16 +1168,24 @@ nsLocalFile::Create(uint32_t aType, uint
     return NS_ERROR_FILE_UNKNOWN_TYPE;
   }
 
   nsresult rv = Resolve();
   if (NS_FAILED(rv) && rv != NS_ERROR_FILE_NOT_FOUND) {
     return rv;
   }
 
+  auto* createFunc = (aType == NORMAL_FILE_TYPE ? do_create : do_mkdir);
+
+  rv = createFunc(this, mResolvedPath, aAttributes);
+
+  if (NS_SUCCEEDED(rv) || NS_ERROR_FILE_ALREADY_EXISTS == rv) {
+    return rv;
+  }
+
   // create directories to target
   //
   // A given local file can be either one of these forms:
   //
   //   - normal:    X:\some\path\on\this\drive
   //                       ^--- start here
   //
   //   - UNC path:  \\machine\volume\some\path\on\this\drive
@@ -1232,25 +1240,17 @@ nsLocalFile::Create(uint32_t aType, uint
     }
   }
 
   // If our last CreateDirectory failed due to access, return that.
   if (NS_ERROR_FILE_ACCESS_DENIED == directoryCreateError) {
     return directoryCreateError;
   }
 
-  if (aType == NORMAL_FILE_TYPE) {
-    return do_create(this, mResolvedPath, aAttributes);
-  }
-
-  if (aType == DIRECTORY_TYPE) {
-    return do_mkdir(this, mResolvedPath, aAttributes);
-  }
-
-  return NS_ERROR_FILE_UNKNOWN_TYPE;
+  return createFunc(this, mResolvedPath, aAttributes);
 }
 
 NS_IMETHODIMP
 nsLocalFile::Append(const nsAString& aNode) {
   // append this path, multiple components are not permitted
   return AppendInternal(PromiseFlatString(aNode), false);
 }