зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1428557 - Stop using GetNativePath in xpcom/. r=froydnj
MozReview-Commit-ID: GnSFQ1wprzb --HG-- extra : rebase_source : 7c25e0361d7f4e8aea730672a931cf78a581e062 extra : intermediate-source : e055aee7306b6636d27abe6fc0b02012b0075260 extra : source : d0831f473c8f85996c106693c9a4ce3783dd9447
This commit is contained in:
Родитель
9bbb2153d4
Коммит
4872102e9d
|
@ -65,12 +65,18 @@ TestStartupCache::TestStartupCache()
|
|||
{
|
||||
NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mSCFile));
|
||||
mSCFile->AppendNative(NS_LITERAL_CSTRING("test-startupcache.tmp"));
|
||||
#ifdef XP_WIN
|
||||
nsAutoString env(NS_LITERAL_STRING("MOZ_STARTUP_CACHE="));
|
||||
env.Append(mSCFile->NativePath());
|
||||
_wputenv(env.get());
|
||||
#else
|
||||
nsAutoCString path;
|
||||
mSCFile->GetNativePath(path);
|
||||
char* env = mozilla::Smprintf("MOZ_STARTUP_CACHE=%s", path.get()).release();
|
||||
PR_SetEnv(env);
|
||||
// We intentionally leak `env` here because it is required by PR_SetEnv
|
||||
MOZ_LSAN_INTENTIONALLY_LEAK_OBJECT(env);
|
||||
#endif
|
||||
StartupCache::GetSingleton()->InvalidateCache();
|
||||
}
|
||||
TestStartupCache::~TestStartupCache()
|
||||
|
|
|
@ -805,12 +805,8 @@ nsMemoryInfoDumper::OpenDMDFile(const nsAString& aIdentifier, int aPid,
|
|||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "OpenANSIFileDesc failed");
|
||||
|
||||
// Print the path, because on some platforms (e.g. Mac) it's not obvious.
|
||||
nsCString path;
|
||||
rv = dmdFile->GetNativePath(path);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
dmd::StatusMsg("opened %s for writing\n", path.get());
|
||||
dmd::StatusMsg("opened %s for writing\n",
|
||||
dmdFile->HumanReadablePath().get());
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
#include "mozilla/Unused.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsLocalFile.h"
|
||||
#include "nsPrintfCString.h"
|
||||
#include "mozilla/StackWalk.h"
|
||||
#include "plstr.h"
|
||||
#include "prio.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#define NS_T(str) L ## str
|
||||
#define NS_SLASH "\\"
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
|
@ -92,21 +92,22 @@ RecordStackWalker(uint32_t aFrameNumber, void* aPC, void* aSP, void* aClosure)
|
|||
*/
|
||||
class LateWriteObserver final : public IOInterposeObserver
|
||||
{
|
||||
using char_type = filesystem::Path::value_type;
|
||||
public:
|
||||
explicit LateWriteObserver(const char* aProfileDirectory)
|
||||
: mProfileDirectory(PL_strdup(aProfileDirectory))
|
||||
explicit LateWriteObserver(const char_type* aProfileDirectory)
|
||||
: mProfileDirectory(NS_strdup(aProfileDirectory))
|
||||
{
|
||||
}
|
||||
~LateWriteObserver()
|
||||
{
|
||||
PL_strfree(mProfileDirectory);
|
||||
free(mProfileDirectory);
|
||||
mProfileDirectory = nullptr;
|
||||
}
|
||||
|
||||
void Observe(IOInterposeObserver::Observation& aObservation) override;
|
||||
|
||||
private:
|
||||
char* mProfileDirectory;
|
||||
char_type* mProfileDirectory;
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -130,9 +131,9 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
|
|||
&rawStack);
|
||||
Telemetry::ProcessedStack stack = Telemetry::GetStackAndModules(rawStack);
|
||||
|
||||
nsPrintfCString nameAux("%s%s%s", mProfileDirectory,
|
||||
NS_SLASH, "Telemetry.LateWriteTmpXXXXXX");
|
||||
char* name;
|
||||
nsTAutoString<char_type> nameAux(mProfileDirectory);
|
||||
nameAux.AppendLiteral(NS_SLASH "Telemetry.LateWriteTmpXXXXXX");
|
||||
char_type* name;
|
||||
nameAux.GetMutableData(&name);
|
||||
|
||||
// We want the sha1 of the entire file, so please don't write to fd
|
||||
|
@ -142,9 +143,9 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
|
|||
HANDLE hFile;
|
||||
do {
|
||||
// mkstemp isn't supported so keep trying until we get a file
|
||||
_mktemp_s(name, strlen(name) + 1);
|
||||
hFile = CreateFileA(name, GENERIC_WRITE, 0, nullptr, CREATE_NEW,
|
||||
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
_wmktemp_s(char16ptr_t(name), NS_strlen(name) + 1);
|
||||
hFile = CreateFileW(char16ptr_t(name), GENERIC_WRITE, 0, nullptr,
|
||||
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
} while (GetLastError() == ERROR_FILE_EXISTS);
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE) {
|
||||
|
@ -202,13 +203,12 @@ LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
|
|||
|
||||
// We append the sha1 of the contents to the file name. This provides a simple
|
||||
// client side deduplication.
|
||||
nsPrintfCString finalName("%s%s", mProfileDirectory,
|
||||
"/Telemetry.LateWriteFinal-");
|
||||
nsAutoString finalName(NS_LITERAL_STRING("Telemetry.LateWriteFinal-"));
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
finalName.AppendPrintf("%02x", sha1[i]);
|
||||
}
|
||||
PR_Delete(finalName.get());
|
||||
PR_Rename(name, finalName.get());
|
||||
RefPtr<nsLocalFile> file = new nsLocalFile(nameAux);
|
||||
file->RenameTo(nullptr, finalName);
|
||||
}
|
||||
|
||||
/******************************* Setup/Teardown *******************************/
|
||||
|
@ -223,9 +223,8 @@ InitLateWriteChecks()
|
|||
nsCOMPtr<nsIFile> mozFile;
|
||||
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mozFile));
|
||||
if (mozFile) {
|
||||
nsAutoCString nativePath;
|
||||
nsresult rv = mozFile->GetNativePath(nativePath);
|
||||
if (NS_SUCCEEDED(rv) && nativePath.get()) {
|
||||
PathString nativePath = mozFile->NativePath();
|
||||
if (nativePath.get()) {
|
||||
sLateWriteObserver = new LateWriteObserver(nativePath.get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,6 +227,11 @@ nsLocalFile::nsLocalFile()
|
|||
{
|
||||
}
|
||||
|
||||
nsLocalFile::nsLocalFile(const nsACString& aFilePath)
|
||||
{
|
||||
InitWithNativePath(aFilePath);
|
||||
}
|
||||
|
||||
nsLocalFile::nsLocalFile(const nsLocalFile& aOther)
|
||||
: mPath(aOther.mPath)
|
||||
{
|
||||
|
|
|
@ -91,6 +91,7 @@ public:
|
|||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
|
||||
|
||||
nsLocalFile();
|
||||
explicit nsLocalFile(const nsACString& aFilePath);
|
||||
|
||||
static nsresult nsLocalFileConstructor(nsISupports* aOuter,
|
||||
const nsIID& aIID,
|
||||
|
|
|
@ -799,6 +799,12 @@ nsLocalFile::nsLocalFile()
|
|||
{
|
||||
}
|
||||
|
||||
nsLocalFile::nsLocalFile(const nsAString& aFilePath)
|
||||
: mFollowSymlinks(false)
|
||||
{
|
||||
InitWithPath(aFilePath);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsLocalFile::nsLocalFileConstructor(nsISupports* aOuter, const nsIID& aIID,
|
||||
void** aInstancePtr)
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_LOCAL_FILE_CID)
|
||||
|
||||
nsLocalFile();
|
||||
explicit nsLocalFile(const nsAString& aFilePath);
|
||||
|
||||
static nsresult nsLocalFileConstructor(nsISupports* aOuter,
|
||||
const nsIID& aIID,
|
||||
|
|
|
@ -31,11 +31,12 @@ static already_AddRefed<nsIFile> NewFile(nsIFile* aBase)
|
|||
return file.forget();
|
||||
}
|
||||
|
||||
static nsCString FixName(const char* aName)
|
||||
template <typename char_type>
|
||||
static nsTString<char_type> FixName(const char_type* aName)
|
||||
{
|
||||
nsCString name;
|
||||
nsTString<char_type> name;
|
||||
for (uint32_t i = 0; aName[i]; ++i) {
|
||||
char ch = aName[i];
|
||||
char_type ch = aName[i];
|
||||
// PR_GetPathSeparator returns the wrong value on Mac so don't use it
|
||||
#if defined(XP_WIN)
|
||||
if (ch == '/') {
|
||||
|
@ -379,22 +380,26 @@ static bool TestNormalizeNativePath(nsIFile* aBase, nsIFile* aStart)
|
|||
if (!file)
|
||||
return false;
|
||||
|
||||
nsAutoCString path;
|
||||
nsresult rv = file->GetNativePath(path);
|
||||
VerifyResult(rv, "GetNativePath");
|
||||
auto path = file->NativePath();
|
||||
#ifdef XP_WIN
|
||||
path.Append(FixName(u"/./.."));
|
||||
nsresult rv = file->InitWithPath(path);
|
||||
VerifyResult(rv, "InitWithPath");
|
||||
#else
|
||||
path.Append(FixName("/./.."));
|
||||
rv = file->InitWithNativePath(path);
|
||||
nsresult rv = file->InitWithNativePath(path);
|
||||
VerifyResult(rv, "InitWithNativePath");
|
||||
#endif
|
||||
rv = file->Normalize();
|
||||
VerifyResult(rv, "Normalize");
|
||||
rv = file->GetNativePath(path);
|
||||
VerifyResult(rv, "GetNativePath (after normalization)");
|
||||
path = file->NativePath();
|
||||
|
||||
nsAutoCString basePath;
|
||||
rv = aBase->GetNativePath(basePath);
|
||||
auto basePath = aBase->NativePath();
|
||||
VerifyResult(rv, "GetNativePath (base)");
|
||||
|
||||
EXPECT_TRUE(path.Equals(basePath)) << "Incorrect normalization: " << path.get() << " - " << basePath.get();
|
||||
EXPECT_TRUE(path.Equals(basePath)) << "Incorrect normalization: " <<
|
||||
file->HumanReadablePath().get() << " - " <<
|
||||
aBase->HumanReadablePath().get();
|
||||
if (!path.Equals(basePath)) {
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче