Bug 1428543 - Add mozilla::filesystem::Path and use it in nsIFile. r=froydnj
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Thu, 28 Dec 2017 03:03:35 +0900
changeset 400947 92b84f3e90499e41d94ebbf7f04d9f9aa8fbce58
parent 400946 7e996018bdd531c271d54415ebd5a41d5f57865f
child 400948 a7b0d7e12748d52e831f9693ad2e13544ebe361f
push id33323
push userapavel@mozilla.com
push dateFri, 26 Jan 2018 17:47:13 +0000
treeherdermozilla-central@831d2c0e7bf9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1428543
milestone60.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 1428543 - Add mozilla::filesystem::Path and use it in nsIFile. r=froydnj Currently only |value_type| is implemented. MozReview-Commit-ID: 1mejzvkuako
mfbt/Path.h
mfbt/moz.build
xpcom/io/FileDescriptorFile.cpp
xpcom/io/nsIFile.idl
xpcom/io/nsLocalFileUnix.cpp
xpcom/io/nsLocalFileWin.cpp
new file mode 100644
--- /dev/null
+++ b/mfbt/Path.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* Represents the native path format on the platform. */
+
+#ifndef mozilla_Path_h
+#define mozilla_Path_h
+
+namespace mozilla {
+namespace filesystem {
+
+/*
+ * Mozilla vaiant of std::filesystem::path.
+ * Only |value_type| is implemented at the moment.
+ */
+class Path
+{
+public:
+#ifdef XP_WIN
+  using value_type = char16_t;
+#else
+  using value_type = char;
+#endif
+};
+
+}  /* namespace filesystem */
+}  /* namespace mozilla */
+
+#endif /* mozilla_Path_h */
--- a/mfbt/moz.build
+++ b/mfbt/moz.build
@@ -58,16 +58,17 @@ EXPORTS.mozilla = [
     'MemoryChecking.h',
     'MemoryReporting.h',
     'Move.h',
     'NotNull.h',
     'NullPtr.h',
     'Opaque.h',
     'OperatorNewExtensions.h',
     'Pair.h',
+    'Path.h',
     'PodOperations.h',
     'Poison.h',
     'Range.h',
     'RangedArray.h',
     'RangedPtr.h',
     'ReentrancyGuard.h',
     'RefCounted.h',
     'RefCountType.h',
--- a/xpcom/io/FileDescriptorFile.cpp
+++ b/xpcom/io/FileDescriptorFile.cpp
@@ -115,20 +115,20 @@ FileDescriptorFile::GetNativeTarget(nsAC
 }
 
 nsresult
 FileDescriptorFile::GetPath(nsAString& aRetVal)
 {
   return mFile->GetPath(aRetVal);
 }
 
-NS_IMETHODIMP
-FileDescriptorFile::GetNativePath(nsACString& aRetVal)
+PathString
+FileDescriptorFile::NativePath()
 {
-  return mFile->GetNativePath(aRetVal);
+  return mFile->NativePath();
 }
 
 NS_IMETHODIMP
 FileDescriptorFile::Equals(nsIFile* aOther, bool* aRetVal)
 {
   return mFile->Equals(aOther, aRetVal);
 }
 
--- a/xpcom/io/nsIFile.idl
+++ b/xpcom/io/nsIFile.idl
@@ -4,21 +4,28 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 %{C++
 struct PRFileDesc;
 struct PRLibrary;
 #include <stdio.h>
+#include "mozilla/Path.h"
+#include "nsStringFwd.h"
+namespace mozilla {
+using PathString = nsTString<filesystem::Path::value_type>;
+using PathSubstring = nsTSubstring<filesystem::Path::value_type>;
+} // namespace mozilla
 %}
 
 [ptr] native PRFileDescStar(PRFileDesc);
 [ptr] native PRLibraryStar(PRLibrary);
 [ptr] native FILE(FILE);
+native PathString(mozilla::PathString);
 
 interface nsISimpleEnumerator;
 
 /**
  * An nsIFile is an abstract representation of a filename. It manages
  * filename encoding issues, pathname component separators ('/' vs. '\\'
  * vs. ':') and weird stuff like differing volumes with identical names, as
  * on pre-Darwin Macintoshes.
@@ -246,17 +253,20 @@ interface nsIFile : nsISupports
      *
      *  Note that the ACString attributes are returned in the 
      *  native filesystem charset.
      *
      */
     readonly attribute AString target;
     [noscript] readonly attribute ACString nativeTarget;
     readonly attribute AString path;
-    [noscript] readonly attribute ACString nativePath;
+    [notxpcom,nostdcall] PathString nativePath();
+%{C++
+    nsresult GetNativePath(nsACString& aPath);
+%}
 
     boolean exists();
     boolean isWritable();
     boolean isReadable();
     boolean isExecutable();
     boolean isHidden();
     boolean isDirectory();
     boolean isFile();
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -586,20 +586,26 @@ NS_IMETHODIMP
 nsLocalFile::SetNativeLeafName(const nsACString& aLeafName)
 {
   nsACString::const_iterator begin, end;
   LocateNativeLeafName(begin, end);
   mPath.Replace(begin.get() - mPath.get(), Distance(begin, end), aLeafName);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsLocalFile::GetNativePath(nsACString& aResult)
+nsCString
+nsLocalFile::NativePath()
 {
-  aResult = mPath;
+  return mPath;
+}
+
+nsresult
+nsIFile::GetNativePath(nsACString& aResult)
+{
+  aResult = NativePath();
   return NS_OK;
 }
 
 nsresult
 nsLocalFile::GetNativeTargetPathName(nsIFile* aNewParent,
                                      const nsACString& aNewName,
                                      nsACString& aResult)
 {
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -3547,27 +3547,27 @@ nsLocalFile::SetNativeLeafName(const nsA
   if (NS_SUCCEEDED(rv)) {
     return SetLeafName(tmp);
   }
 
   return rv;
 }
 
 
-NS_IMETHODIMP
-nsLocalFile::GetNativePath(nsACString& aResult)
+nsString
+nsLocalFile::NativePath()
+{
+  return mWorkingPath;
+}
+
+nsresult
+nsIFile::GetNativePath(nsACString& aResult)
 {
   //NS_WARNING("This API is lossy. Use GetPath !");
-  nsAutoString tmp;
-  nsresult rv = GetPath(tmp);
-  if (NS_SUCCEEDED(rv)) {
-    rv = NS_CopyUnicodeToNative(tmp, aResult);
-  }
-
-  return rv;
+  return NS_CopyUnicodeToNative(NativePath(), aResult);
 }
 
 
 NS_IMETHODIMP
 nsLocalFile::GetNativeCanonicalPath(nsACString& aResult)
 {
   NS_WARNING("This method is lossy. Use GetCanonicalPath !");
   EnsureShortPath();