Bug 1428543 - Add nsIFile::HumanReadablePath. r?froydnj draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 30 Dec 2017 23:32:27 +0900
changeset 747574 1ebd5b1cef627771fdd67abb02240fa05e620f50
parent 747573 033ad22d426105c348670bc2bc339955f64812ad
child 747575 f6831c62d891a09a68f85af23a788ecf68df4393
push id96939
push userVYV03354@nifty.ne.jp
push dateFri, 26 Jan 2018 11:24:45 +0000
reviewersfroydnj
bugs1428543
milestone60.0a1
Bug 1428543 - Add nsIFile::HumanReadablePath. r?froydnj This method is used to replace some GetNativePath usage for logging. MozReview-Commit-ID: 9nWf2r4oviA
xpcom/io/nsIFile.idl
xpcom/io/nsLocalFileUnix.cpp
xpcom/io/nsLocalFileWin.cpp
--- a/xpcom/io/nsIFile.idl
+++ b/xpcom/io/nsIFile.idl
@@ -253,19 +253,23 @@ 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;
-    [notxpcom,nostdcall] PathString nativePath();
+    [notxpcom,nostdcall,must_use] PathString nativePath();
 %{C++
     nsresult GetNativePath(nsACString& aPath);
+    /*
+     * Returns a human-readable path string.
+     */
+    nsCString HumanReadablePath();
 %}
 
     boolean exists();
     boolean isWritable();
     boolean isReadable();
     boolean isExecutable();
     boolean isHidden();
     boolean isDirectory();
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * Implementation of nsIFile for "unixy" systems.
  */
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/DebugOnly.h"
 #include "mozilla/Sprintf.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <utime.h>
@@ -599,16 +600,25 @@ nsLocalFile::NativePath()
 
 nsresult
 nsIFile::GetNativePath(nsACString& aResult)
 {
   aResult = NativePath();
   return NS_OK;
 }
 
+nsCString
+nsIFile::HumanReadablePath()
+{
+  nsCString path;
+  DebugOnly<nsresult> rv = GetNativePath(path);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
+  return path;
+}
+
 nsresult
 nsLocalFile::GetNativeTargetPathName(nsIFile* aNewParent,
                                      const nsACString& aNewName,
                                      nsACString& aResult)
 {
   nsresult rv;
   nsCOMPtr<nsIFile> oldParent;
 
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -3560,16 +3560,25 @@ nsLocalFile::NativePath()
 
 nsresult
 nsIFile::GetNativePath(nsACString& aResult)
 {
   //NS_WARNING("This API is lossy. Use GetPath !");
   return NS_CopyUnicodeToNative(NativePath(), aResult);
 }
 
+nsCString
+nsIFile::HumanReadablePath()
+{
+  nsString path;
+  DebugOnly<nsresult> rv = GetPath(path);
+  MOZ_ASSERT(NS_SUCCEEDED(rv));
+  return NS_ConvertUTF16toUTF8(path);
+}
+
 
 NS_IMETHODIMP
 nsLocalFile::GetNativeCanonicalPath(nsACString& aResult)
 {
   NS_WARNING("This method is lossy. Use GetCanonicalPath !");
   EnsureShortPath();
   NS_CopyUnicodeToNative(mShortWorkingPath, aResult);
   return NS_OK;