Bug 685236 - Stop using GetNativePath in netwerk/. r=mayhemer
MozReview-Commit-ID: JdHhXPiS0fv
--- a/netwerk/base/nsDirectoryIndexStream.cpp
+++ b/netwerk/base/nsDirectoryIndexStream.cpp
@@ -84,21 +84,19 @@ nsDirectoryIndexStream::Init(nsIFile* aD
bool isDir;
rv = aDir->IsDirectory(&isDir);
if (NS_FAILED(rv)) return rv;
NS_PRECONDITION(isDir, "not a directory");
if (!isDir)
return NS_ERROR_ILLEGAL_VALUE;
if (MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
- nsAutoCString path;
- aDir->GetNativePath(path);
MOZ_LOG(gLog, LogLevel::Debug,
("nsDirectoryIndexStream[%p]: initialized on %s",
- this, path.get()));
+ this, aDir->HumanReadablePath().get()));
}
// Sigh. We have to allocate on the heap because there are no
// assignment operators defined.
nsCOMPtr<nsISimpleEnumerator> iter;
rv = aDir->GetDirectoryEntries(getter_AddRefs(iter));
if (NS_FAILED(rv)) return rv;
@@ -223,21 +221,19 @@ nsDirectoryIndexStream::Read(char* aBuf,
if (!more) break;
// don't addref, for speed - an addref happened when it
// was placed in the array, so it's not going to go stale
nsIFile* current = mArray.ObjectAt(mPos);
++mPos;
if (MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
- nsAutoCString path;
- current->GetNativePath(path);
MOZ_LOG(gLog, LogLevel::Debug,
("nsDirectoryIndexStream[%p]: iterated %s",
- this, path.get()));
+ this, current->HumanReadablePath().get()));
}
// rjc: don't return hidden files/directories!
// bbaetz: why not?
nsresult rv;
#ifndef XP_UNIX
bool hidden = false;
current->IsHidden(&hidden);
--- a/netwerk/base/nsSocketTransport2.cpp
+++ b/netwerk/base/nsSocketTransport2.cpp
@@ -924,39 +924,37 @@ nsSocketTransport::Init(const char **typ
mProxyTransparentResolvesHost = true;
}
}
}
return NS_OK;
}
+#if defined(XP_UNIX)
nsresult
nsSocketTransport::InitWithFilename(const char *filename)
{
-#if defined(XP_UNIX)
size_t filenameLength = strlen(filename);
if (filenameLength > sizeof(mNetAddr.local.path) - 1)
return NS_ERROR_FILE_NAME_TOO_LONG;
mHost.Assign(filename);
mPort = 0;
mTypeCount = 0;
mNetAddr.local.family = AF_LOCAL;
memcpy(mNetAddr.local.path, filename, filenameLength);
mNetAddr.local.path[filenameLength] = '\0';
mNetAddrIsSet = true;
return NS_OK;
-#else
- return NS_ERROR_SOCKET_ADDRESS_NOT_SUPPORTED;
+}
#endif
-}
nsresult
nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const NetAddr *addr)
{
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
NS_ASSERTION(!mFD.IsInitialized(), "already initialized");
char buf[kNetAddrMaxCStrBufSize];
--- a/netwerk/base/nsSocketTransport2.h
+++ b/netwerk/base/nsSocketTransport2.h
@@ -140,20 +140,22 @@ public:
const NetAddr *addr);
// this method instructs the socket transport to use an already connected
// socket with the given address, and additionally supplies security info.
nsresult InitWithConnectedSocket(PRFileDesc* aSocketFD,
const NetAddr* aAddr,
nsISupports* aSecInfo);
+#ifdef XP_UNIX
// This method instructs the socket transport to open a socket
// connected to the given Unix domain address. We can only create
// unlayered, simple, stream sockets.
nsresult InitWithFilename(const char *filename);
+#endif
// nsASocketHandler methods:
void OnSocketReady(PRFileDesc *, int16_t outFlags) override;
void OnSocketDetached(PRFileDesc *) override;
void IsLocal(bool *aIsLocal) override;
void OnKeepaliveEnabledPrefChange(bool aEnabled) override final;
// called when a socket event is handled
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -750,16 +750,17 @@ nsSocketTransportService::CreateRoutedTr
trans.forget(result);
return NS_OK;
}
NS_IMETHODIMP
nsSocketTransportService::CreateUnixDomainTransport(nsIFile *aPath,
nsISocketTransport **result)
{
+#ifdef XP_UNIX
nsresult rv;
NS_ENSURE_TRUE(mInitialized, NS_ERROR_NOT_INITIALIZED);
nsAutoCString path;
rv = aPath->GetNativePath(path);
if (NS_FAILED(rv))
return rv;
@@ -767,16 +768,19 @@ nsSocketTransportService::CreateUnixDoma
RefPtr<nsSocketTransport> trans = new nsSocketTransport();
rv = trans->InitWithFilename(path.get());
if (NS_FAILED(rv))
return rv;
trans.forget(result);
return NS_OK;
+#else
+ return NS_ERROR_SOCKET_ADDRESS_NOT_SUPPORTED;
+#endif
}
NS_IMETHODIMP
nsSocketTransportService::OnDispatchedEvent()
{
#ifndef XP_WIN
// On windows poll can hang and this became worse when we introduced the
// patch for bug 698882 (see also bug 1292181), therefore we reverted the
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -3235,20 +3235,18 @@ nsStandardURL::GetFile(nsIFile **result)
{
NS_PRECONDITION(mSupportsFileURL,
"GetFile() called on a URL that doesn't support files!");
nsresult rv = EnsureFile();
if (NS_FAILED(rv))
return rv;
if (LOG_ENABLED()) {
- nsAutoCString path;
- mFile->GetNativePath(path);
LOG(("nsStandardURL::GetFile [this=%p spec=%s resulting_path=%s]\n",
- this, mSpec.get(), path.get()));
+ this, mSpec.get(), mFile->HumanReadablePath().get()));
}
// clone the file, so the caller can modify it.
// XXX nsIFileURL.idl specifies that the consumer must _not_ modify the
// nsIFile returned from this method; but it seems that some folks do
// (see bug 161921). until we can be sure that all the consumers are
// behaving themselves, we'll stay on the safe side and clone the file.
// see bug 212724 about fixing the consumers.
--- a/netwerk/cache/nsCache.cpp
+++ b/netwerk/cache/nsCache.cpp
@@ -15,24 +15,17 @@
* Cache Service Utility Functions
*/
mozilla::LazyLogModule gCacheLog("cache");
void
CacheLogPrintPath(mozilla::LogLevel level, const char * format, nsIFile * item)
{
- nsAutoCString path;
- nsresult rv = item->GetNativePath(path);
- if (NS_SUCCEEDED(rv)) {
- MOZ_LOG(gCacheLog, level, (format, path.get()));
- } else {
- MOZ_LOG(gCacheLog, level, ("GetNativePath failed: %" PRIx32,
- static_cast<uint32_t>(rv)));
- }
+ MOZ_LOG(gCacheLog, level, (format, item->HumanReadablePath().get()));
}
uint32_t
SecondsFromPRTime(PRTime prTime)
{
int64_t microSecondsPerSecond = PR_USEC_PER_SEC;
return uint32_t(prTime / microSecondsPerSecond);
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -1,23 +1,25 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set ts=8 sts=4 et sw=4 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/. */
+#include "nsCacheService.h"
+
#include "mozilla/ArrayUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/Assertions.h"
#include "mozilla/DebugOnly.h"
+#include "mozilla/FileUtils.h"
#include "necko-config.h"
#include "nsCache.h"
-#include "nsCacheService.h"
#include "nsCacheRequest.h"
#include "nsCacheEntry.h"
#include "nsCacheEntryDescriptor.h"
#include "nsCacheDevice.h"
#include "nsMemoryCacheDevice.h"
#include "nsICacheVisitor.h"
#include "nsDiskCacheDevice.h"
#include "nsDiskCacheDeviceSQL.h"
@@ -1759,20 +1761,18 @@ nsCacheService::CreateOfflineDevice()
nsresult
nsCacheService::CreateCustomOfflineDevice(nsIFile *aProfileDir,
int32_t aQuota,
nsOfflineCacheDevice **aDevice)
{
NS_ENSURE_ARG(aProfileDir);
if (MOZ_LOG_TEST(gCacheLog, LogLevel::Info)) {
- nsAutoCString profilePath;
- aProfileDir->GetNativePath(profilePath);
CACHE_LOG_INFO(("Creating custom offline device, %s, %d",
- profilePath.BeginReading(), aQuota));
+ aProfileDir->HumanReadablePath().get(), aQuota));
}
if (!mInitialized) return NS_ERROR_NOT_AVAILABLE;
if (!mEnableOfflineDevice) return NS_ERROR_NOT_AVAILABLE;
*aDevice = new nsOfflineCacheDevice;
NS_ADDREF(*aDevice);
@@ -3123,34 +3123,34 @@ nsCacheService::MoveOrRemoveDiskCache(ns
nsCOMPtr<nsIFile> aNewCacheSubdir;
aNewCacheDir->Clone(getter_AddRefs(aNewCacheSubdir));
rv = aNewCacheSubdir->AppendNative(nsDependentCString(aCacheSubdir));
if (NS_FAILED(rv))
return;
- nsAutoCString newPath;
- rv = aNewCacheSubdir->GetNativePath(newPath);
- if (NS_FAILED(rv))
- return;
+ PathString newPath = aNewCacheSubdir->NativePath();
if (NS_SUCCEEDED(aNewCacheSubdir->Exists(&exists)) && !exists) {
// New cache directory does not exist, try to move the old one here
// rename needs an empty target directory
// Make sure the parent of the target sub-dir exists
rv = aNewCacheDir->Create(nsIFile::DIRECTORY_TYPE, 0777);
if (NS_SUCCEEDED(rv) || NS_ERROR_FILE_ALREADY_EXISTS == rv) {
- nsAutoCString oldPath;
- rv = aOldCacheSubdir->GetNativePath(oldPath);
- if (NS_FAILED(rv))
+ PathString oldPath = aOldCacheSubdir->NativePath();
+#ifdef XP_WIN
+ if (MoveFileW(oldPath.get(), newPath.get()))
+#else
+ if (rename(oldPath.get(), newPath.get()) == 0)
+#endif
+ {
return;
- if (rename(oldPath.get(), newPath.get()) == 0)
- return;
+ }
}
}
// Delay delete by 1 minute to avoid IO thrash on startup.
nsDeleteDir::DeleteDir(aOldCacheSubdir, false, 60000);
}
static bool
--- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp
+++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp
@@ -283,19 +283,17 @@ nsOfflineCacheEvictionFunction::Apply()
return;
}
appcachedetail::FileArray items;
items.SwapElements(*pitems);
for (int32_t i = 0; i < items.Count(); i++) {
if (MOZ_LOG_TEST(gCacheLog, LogLevel::Debug)) {
- nsAutoCString path;
- items[i]->GetNativePath(path);
- LOG((" removing %s\n", path.get()));
+ LOG((" removing %s\n", items[i]->HumanReadablePath().get()));
}
items[i]->Remove(false);
}
}
class nsOfflineCacheDiscardCache : public Runnable
{
--- a/netwerk/cache2/CacheFileContextEvictor.cpp
+++ b/netwerk/cache2/CacheFileContextEvictor.cpp
@@ -273,18 +273,17 @@ CacheFileContextEvictor::PersistEviction
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
nsCOMPtr<nsIFile> file;
rv = GetContextFile(aLoadContextInfo, aPinned, getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- nsAutoCString path;
- file->GetNativePath(path);
+ nsCString path = file->HumanReadablePath();
PRFileDesc *fd;
rv = file->OpenNSPRFileDesc(PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 0600,
&fd);
if (NS_WARN_IF(NS_FAILED(rv))) {
LOG(("CacheFileContextEvictor::PersistEvictionInfoToDisk() - Creating file "
"failed! [path=%s, rv=0x%08" PRIx32 "]", path.get(), static_cast<uint32_t>(rv)));
return rv;
@@ -310,18 +309,17 @@ CacheFileContextEvictor::RemoveEvictInfo
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
nsCOMPtr<nsIFile> file;
rv = GetContextFile(aLoadContextInfo, aPinned, getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- nsAutoCString path;
- file->GetNativePath(path);
+ nsCString path = file->HumanReadablePath();
rv = file->Remove(false);
if (NS_WARN_IF(NS_FAILED(rv))) {
LOG(("CacheFileContextEvictor::RemoveEvictionInfoFromDisk() - Removing file"
" failed! [path=%s, rv=0x%08" PRIx32 "]", path.get(), static_cast<uint32_t>(rv)));
return rv;
}
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -3314,19 +3314,18 @@ CacheFileIOManager::CacheIndexStateChang
mContextEvictor->CacheIndexStateChanged();
return NS_OK;
}
nsresult
CacheFileIOManager::TrashDirectory(nsIFile *aFile)
{
- nsAutoCString path;
- aFile->GetNativePath(path);
- LOG(("CacheFileIOManager::TrashDirectory() [file=%s]", path.get()));
+ LOG(("CacheFileIOManager::TrashDirectory() [file=%s]",
+ aFile->HumanReadablePath().get()));
nsresult rv;
MOZ_ASSERT(mIOThread->IsCurrentThread());
MOZ_ASSERT(mCacheDirectory);
// When the directory is empty, it is cheaper to remove it directly instead of
// using the trash mechanism.
@@ -3554,21 +3553,19 @@ CacheFileIOManager::RemoveTrashInternal(
continue; // check elapsed time
} else {
bool isDir = false;
file->IsDirectory(&isDir);
if (isDir) {
NS_WARNING("Found a directory in a trash directory! It will be removed "
"recursively, but this can block IO thread for a while!");
if (LOG_ENABLED()) {
- nsAutoCString path;
- file->GetNativePath(path);
LOG(("CacheFileIOManager::RemoveTrashInternal() - Found a directory in a trash "
"directory! It will be removed recursively, but this can block IO "
- "thread for a while! [file=%s]", path.get()));
+ "thread for a while! [file=%s]", file->HumanReadablePath().get()));
}
}
file->Remove(isDir);
}
}
NS_NOTREACHED("We should never get here");
return NS_OK;
@@ -4147,20 +4144,18 @@ CacheFileIOManager::SyncRemoveDir(nsIFil
rv = file->AppendNative(nsDependentCString(aDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
if (LOG_ENABLED()) {
- nsAutoCString path;
- file->GetNativePath(path);
LOG(("CacheFileIOManager::SyncRemoveDir() - Removing directory %s",
- path.get()));
+ file->HumanReadablePath().get()));
}
rv = file->Remove(true);
if (NS_WARN_IF(NS_FAILED(rv))) {
LOG(("CacheFileIOManager::SyncRemoveDir() - Removing failed! [rv=0x%08" PRIx32 "]",
static_cast<uint32_t>(rv)));
}
--- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp
@@ -604,23 +604,19 @@ ExtensionProtocolHandler::AppDirContains
#endif /* !defined(XP_WIN) */
static void
LogExternalResourceError(nsIFile* aExtensionDir, nsIFile* aRequestedFile)
{
MOZ_ASSERT(aExtensionDir);
MOZ_ASSERT(aRequestedFile);
- nsAutoCString extensionDirPath, requestedFilePath;
- Unused << aExtensionDir->GetNativePath(extensionDirPath);
- Unused << aRequestedFile->GetNativePath(requestedFilePath);
-
LOG("Rejecting external unpacked extension resource [%s] from "
- "extension directory [%s]", requestedFilePath.get(),
- extensionDirPath.get());
+ "extension directory [%s]", aRequestedFile->HumanReadablePath().get(),
+ aExtensionDir->HumanReadablePath().get());
}
Result<nsCOMPtr<nsIInputStream>, nsresult>
ExtensionProtocolHandler::NewStream(nsIURI* aChildURI, bool* aTerminateSender)
{
MOZ_ASSERT(!IsNeckoChild());
MOZ_TRY(aChildURI ? NS_OK : NS_ERROR_INVALID_ARG);
MOZ_TRY(aTerminateSender ? NS_OK : NS_ERROR_INVALID_ARG);