Bug 1428543 - Add nsIFile::HumanReadablePath. r?froydnj
This method is used to replace some GetNativePath usage for logging.
MozReview-Commit-ID: 9nWf2r4oviA
--- 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;