Bug 685236 - Add nsIFile::DisplayPath. r?froydnj
This method is used to replace some GetNativePath usage for logging.
MozReview-Commit-ID: 9nWf2r4oviA
--- a/xpcom/io/FileDescriptorFile.cpp
+++ b/xpcom/io/FileDescriptorFile.cpp
@@ -121,16 +121,22 @@ FileDescriptorFile::GetPath(nsAString& a
}
filesystem::Path::string_type
FileDescriptorFile::NativePath()
{
return mFile->NativePath();
}
+nsCString
+FileDescriptorFile::DisplayPath()
+{
+ return mFile->DisplayPath();
+}
+
NS_IMETHODIMP
FileDescriptorFile::Equals(nsIFile* aOther, bool* aRetVal)
{
return mFile->Equals(aOther, aRetVal);
}
NS_IMETHODIMP
FileDescriptorFile::Contains(nsIFile* aOther, bool* aRetVal)
--- a/xpcom/io/nsIFile.idl
+++ b/xpcom/io/nsIFile.idl
@@ -11,16 +11,17 @@ struct PRLibrary;
#include <stdio.h>
#include "mozilla/Path.h"
%}
[ptr] native PRFileDescStar(PRFileDesc);
[ptr] native PRLibraryStar(PRLibrary);
[ptr] native FILE(FILE);
native PathString(mozilla::filesystem::Path::string_type);
+native UTF8String(nsCString);
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.
@@ -248,20 +249,25 @@ 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.
+ * The result is deliberately quoted to prevent abuse.
+ */
+ [notxpcom,nostdcall,must_use] UTF8String displayPath();
boolean exists();
boolean isWritable();
boolean isReadable();
boolean isExecutable();
boolean isHidden();
boolean isDirectory();
boolean isFile();
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -603,16 +603,25 @@ nsLocalFile::NativePath()
nsresult
nsIFile::GetNativePath(nsACString& aResult)
{
aResult = NativePath();
return NS_OK;
}
+nsCString
+nsLocalFile::DisplayPath()
+{
+ nsAutoCString path('[');
+ path.Append(mPath);
+ path.Append(']');
+ return mPath;
+}
+
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
+nsLocalFile::DisplayPath()
+{
+ nsAutoCString path('[');
+ AppendUTF16toUTF8(mWorkingPath, path);
+ path.Append(']');
+ return path;
+}
+
NS_IMETHODIMP
nsLocalFile::GetNativeCanonicalPath(nsACString& aResult)
{
NS_WARNING("This method is lossy. Use GetCanonicalPath !");
EnsureShortPath();
NS_CopyUnicodeToNative(mShortWorkingPath, aResult);
return NS_OK;