2019-01-19 01:52:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 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 "QuotaCommon.h"
|
|
|
|
|
2021-05-25 12:06:11 +03:00
|
|
|
#ifdef QM_ERROR_STACKS_ENABLED
|
|
|
|
# include "base/process_util.h"
|
|
|
|
#endif
|
2020-12-04 17:56:18 +03:00
|
|
|
#include "mozIStorageConnection.h"
|
|
|
|
#include "mozIStorageStatement.h"
|
2020-12-21 12:32:12 +03:00
|
|
|
#include "mozilla/ErrorNames.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2020-12-09 23:01:07 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/TelemetryComms.h"
|
|
|
|
#include "mozilla/TelemetryEventEnums.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "mozilla/TextUtils.h"
|
2021-11-30 08:05:51 +03:00
|
|
|
#include "mozilla/dom/quota/ResultExtensions.h"
|
2021-06-25 13:21:27 +03:00
|
|
|
#include "mozilla/dom/quota/ScopedLogExtraInfo.h"
|
2020-09-08 10:40:46 +03:00
|
|
|
#include "nsIConsoleService.h"
|
2020-04-01 10:26:27 +03:00
|
|
|
#include "nsIFile.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsStringFlags.h"
|
|
|
|
#include "nsTStringRepr.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
2020-04-06 12:28:35 +03:00
|
|
|
#include "nsXPCOM.h"
|
|
|
|
#include "nsXULAppAPI.h"
|
2020-10-21 16:16:19 +03:00
|
|
|
|
2020-04-01 10:26:27 +03:00
|
|
|
#ifdef XP_WIN
|
2020-10-21 16:16:19 +03:00
|
|
|
# include "mozilla/Atomics.h"
|
2020-04-06 12:28:35 +03:00
|
|
|
# include "mozilla/ipc/BackgroundParent.h"
|
|
|
|
# include "mozilla/StaticPrefs_dom.h"
|
2020-04-01 10:26:27 +03:00
|
|
|
# include "nsILocalFileWin.h"
|
|
|
|
#endif
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom::quota {
|
2019-03-21 23:08:00 +03:00
|
|
|
|
2020-12-09 23:01:07 +03:00
|
|
|
using namespace mozilla::Telemetry;
|
|
|
|
|
2019-03-21 23:08:00 +03:00
|
|
|
namespace {
|
|
|
|
|
2020-06-25 10:16:47 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
constexpr auto kDSStoreFileName = u".DS_Store"_ns;
|
|
|
|
constexpr auto kDesktopFileName = u".desktop"_ns;
|
|
|
|
constexpr auto kDesktopIniFileName = u"desktop.ini"_ns;
|
|
|
|
constexpr auto kThumbsDbFileName = u"thumbs.db"_ns;
|
|
|
|
#endif
|
|
|
|
|
2020-04-06 12:28:35 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
Atomic<int32_t> gUseDOSDevicePathSyntax(-1);
|
|
|
|
#endif
|
|
|
|
|
2019-03-21 23:08:00 +03:00
|
|
|
LazyLogModule gLogger("QuotaManager");
|
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
void AnonymizeCString(nsACString& aCString, uint32_t aStart) {
|
|
|
|
MOZ_ASSERT(!aCString.IsEmpty());
|
|
|
|
MOZ_ASSERT(aStart < aCString.Length());
|
2019-01-19 01:52:06 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
char* iter = aCString.BeginWriting() + aStart;
|
|
|
|
char* end = aCString.EndWriting();
|
2019-06-09 22:46:34 +03:00
|
|
|
|
|
|
|
while (iter != end) {
|
|
|
|
char c = *iter;
|
|
|
|
|
|
|
|
if (IsAsciiAlpha(c)) {
|
|
|
|
*iter = 'a';
|
|
|
|
} else if (IsAsciiDigit(c)) {
|
|
|
|
*iter = 'D';
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
} // namespace
|
2019-06-09 22:46:34 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
const char kQuotaGenericDelimiter = '|';
|
2019-06-09 22:46:34 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
#ifdef NIGHTLY_BUILD
|
|
|
|
const nsLiteralCString kQuotaInternalError = "internal"_ns;
|
|
|
|
const nsLiteralCString kQuotaExternalError = "external"_ns;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LogModule* GetQuotaManagerLogger() { return gLogger; }
|
|
|
|
|
|
|
|
void AnonymizeCString(nsACString& aCString) {
|
|
|
|
if (aCString.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AnonymizeCString(aCString, /* aStart */ 0);
|
|
|
|
}
|
2019-06-09 22:46:34 +03:00
|
|
|
|
2019-10-02 07:28:23 +03:00
|
|
|
void AnonymizeOriginString(nsACString& aOriginString) {
|
|
|
|
if (aOriginString.IsEmpty()) {
|
|
|
|
return;
|
2019-06-09 22:46:34 +03:00
|
|
|
}
|
2019-10-02 07:28:23 +03:00
|
|
|
|
|
|
|
int32_t start = aOriginString.FindChar(':');
|
|
|
|
if (start < 0) {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnonymizeCString(aOriginString, start);
|
2019-06-09 22:46:34 +03:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:28:35 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
void CacheUseDOSDevicePathSyntaxPrefValue() {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2021-08-25 13:46:15 +03:00
|
|
|
::mozilla::ipc::AssertIsOnBackgroundThread();
|
2020-04-06 12:28:35 +03:00
|
|
|
|
|
|
|
if (gUseDOSDevicePathSyntax == -1) {
|
|
|
|
bool useDOSDevicePathSyntax =
|
|
|
|
StaticPrefs::dom_quotaManager_useDOSDevicePathSyntax_DoNotUseDirectly();
|
|
|
|
gUseDOSDevicePathSyntax = useDOSDevicePathSyntax ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-01 10:26:27 +03:00
|
|
|
Result<nsCOMPtr<nsIFile>, nsresult> QM_NewLocalFile(const nsAString& aPath) {
|
2021-11-30 08:05:53 +03:00
|
|
|
QM_TRY_UNWRAP(
|
|
|
|
auto file,
|
|
|
|
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, NS_NewLocalFile, aPath,
|
|
|
|
/* aFollowLinks */ false),
|
|
|
|
QM_PROPAGATE, [&aPath](const nsresult rv) {
|
|
|
|
QM_WARNING("Failed to construct a file for path (%s)",
|
|
|
|
NS_ConvertUTF16toUTF8(aPath).get());
|
|
|
|
});
|
2020-04-01 10:26:27 +03:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2020-04-06 12:28:35 +03:00
|
|
|
MOZ_ASSERT(gUseDOSDevicePathSyntax != -1);
|
2020-04-01 10:26:27 +03:00
|
|
|
|
2020-04-06 12:28:35 +03:00
|
|
|
if (gUseDOSDevicePathSyntax) {
|
2021-10-11 09:00:15 +03:00
|
|
|
QM_TRY_INSPECT(
|
|
|
|
const auto& winFile,
|
|
|
|
MOZ_TO_RESULT_GET_TYPED(nsCOMPtr<nsILocalFileWin>,
|
|
|
|
MOZ_SELECT_OVERLOAD(do_QueryInterface), file));
|
2020-04-06 12:28:35 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(winFile);
|
|
|
|
winFile->SetUseDOSDevicePathSyntax(true);
|
|
|
|
}
|
2020-04-01 10:26:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2020-09-08 10:40:46 +03:00
|
|
|
nsDependentCSubstring GetLeafName(const nsACString& aPath) {
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
aPath.BeginReading(start);
|
|
|
|
aPath.EndReading(end);
|
|
|
|
|
|
|
|
bool found = RFindInReadable("/"_ns, start, end);
|
|
|
|
if (found) {
|
|
|
|
start = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPath.EndReading(end);
|
|
|
|
|
|
|
|
return nsDependentCSubstring(start.get(), end.get());
|
|
|
|
}
|
|
|
|
|
2020-10-26 17:51:32 +03:00
|
|
|
Result<nsCOMPtr<nsIFile>, nsresult> CloneFileAndAppend(
|
|
|
|
nsIFile& aDirectory, const nsAString& aPathElement) {
|
2021-11-30 08:05:53 +03:00
|
|
|
QM_TRY_UNWRAP(auto resultFile, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
|
|
|
|
nsCOMPtr<nsIFile>, aDirectory, Clone));
|
2020-10-26 17:51:32 +03:00
|
|
|
|
2021-09-24 16:08:29 +03:00
|
|
|
QM_TRY(MOZ_TO_RESULT(resultFile->Append(aPathElement)));
|
2020-10-26 17:51:32 +03:00
|
|
|
|
|
|
|
return resultFile;
|
|
|
|
}
|
|
|
|
|
2021-01-21 17:38:30 +03:00
|
|
|
Result<nsIFileKind, nsresult> GetDirEntryKind(nsIFile& aFile) {
|
2021-04-28 10:33:55 +03:00
|
|
|
// Callers call this function without checking if the directory already
|
2021-05-30 14:08:02 +03:00
|
|
|
// exists (idempotent usage). QM_OR_ELSE_WARN_IF is not used here since we
|
|
|
|
// just want to log NS_ERROR_FILE_NOT_FOUND,
|
|
|
|
// NS_ERROR_FILE_TARGET_DOES_NOT_EXIST and NS_ERROR_FILE_FS_CORRUPTED results
|
|
|
|
// and not spam the reports.
|
2021-06-01 15:12:27 +03:00
|
|
|
QM_TRY_RETURN(QM_OR_ELSE_LOG_VERBOSE_IF(
|
2021-11-30 08:05:53 +03:00
|
|
|
MOZ_TO_RESULT_INVOKE_MEMBER(aFile, IsDirectory)
|
|
|
|
.map([](const bool isDirectory) {
|
|
|
|
return isDirectory ? nsIFileKind::ExistsAsDirectory
|
|
|
|
: nsIFileKind::ExistsAsFile;
|
|
|
|
}),
|
2021-05-30 14:08:02 +03:00
|
|
|
([](const nsresult rv) {
|
|
|
|
return rv == NS_ERROR_FILE_NOT_FOUND ||
|
|
|
|
rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ||
|
|
|
|
// We treat NS_ERROR_FILE_FS_CORRUPTED as if the file did not
|
|
|
|
// exist at all.
|
|
|
|
rv == NS_ERROR_FILE_FS_CORRUPTED;
|
|
|
|
}),
|
|
|
|
ErrToOk<nsIFileKind::DoesNotExist>));
|
2021-01-21 17:38:30 +03:00
|
|
|
}
|
|
|
|
|
2020-12-04 18:15:31 +03:00
|
|
|
Result<nsCOMPtr<mozIStorageStatement>, nsresult> CreateStatement(
|
|
|
|
mozIStorageConnection& aConnection, const nsACString& aStatementString) {
|
2021-11-30 08:05:53 +03:00
|
|
|
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
|
|
|
|
nsCOMPtr<mozIStorageStatement>, aConnection, CreateStatement,
|
|
|
|
aStatementString));
|
2020-12-04 18:15:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <SingleStepResult ResultHandling>
|
|
|
|
Result<SingleStepSuccessType<ResultHandling>, nsresult> ExecuteSingleStep(
|
|
|
|
nsCOMPtr<mozIStorageStatement>&& aStatement) {
|
|
|
|
QM_TRY_INSPECT(const bool& hasResult,
|
2021-11-30 08:05:53 +03:00
|
|
|
MOZ_TO_RESULT_INVOKE_MEMBER(aStatement, ExecuteStep));
|
2020-12-04 18:15:31 +03:00
|
|
|
|
|
|
|
if constexpr (ResultHandling == SingleStepResult::AssertHasResult) {
|
|
|
|
MOZ_ASSERT(hasResult);
|
|
|
|
(void)hasResult;
|
|
|
|
|
|
|
|
return WrapNotNullUnchecked(std::move(aStatement));
|
|
|
|
} else {
|
|
|
|
return hasResult ? std::move(aStatement) : nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template Result<SingleStepSuccessType<SingleStepResult::AssertHasResult>,
|
|
|
|
nsresult>
|
|
|
|
ExecuteSingleStep<SingleStepResult::AssertHasResult>(
|
|
|
|
nsCOMPtr<mozIStorageStatement>&&);
|
|
|
|
|
|
|
|
template Result<SingleStepSuccessType<SingleStepResult::ReturnNullIfNoResult>,
|
|
|
|
nsresult>
|
|
|
|
ExecuteSingleStep<SingleStepResult::ReturnNullIfNoResult>(
|
|
|
|
nsCOMPtr<mozIStorageStatement>&&);
|
|
|
|
|
2020-12-04 18:10:07 +03:00
|
|
|
template <SingleStepResult ResultHandling>
|
|
|
|
Result<SingleStepSuccessType<ResultHandling>, nsresult>
|
2020-12-04 17:56:18 +03:00
|
|
|
CreateAndExecuteSingleStepStatement(mozIStorageConnection& aConnection,
|
|
|
|
const nsACString& aStatementString) {
|
2021-11-30 08:05:53 +03:00
|
|
|
QM_TRY_UNWRAP(auto stmt, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
|
2020-12-04 17:56:18 +03:00
|
|
|
nsCOMPtr<mozIStorageStatement>, aConnection,
|
|
|
|
CreateStatement, aStatementString));
|
|
|
|
|
2020-12-04 18:15:31 +03:00
|
|
|
return ExecuteSingleStep<ResultHandling>(std::move(stmt));
|
2020-12-04 17:56:18 +03:00
|
|
|
}
|
|
|
|
|
2020-12-04 18:10:07 +03:00
|
|
|
template Result<SingleStepSuccessType<SingleStepResult::AssertHasResult>,
|
|
|
|
nsresult>
|
|
|
|
CreateAndExecuteSingleStepStatement<SingleStepResult::AssertHasResult>(
|
|
|
|
mozIStorageConnection& aConnection, const nsACString& aStatementString);
|
|
|
|
|
|
|
|
template Result<SingleStepSuccessType<SingleStepResult::ReturnNullIfNoResult>,
|
|
|
|
nsresult>
|
|
|
|
CreateAndExecuteSingleStepStatement<SingleStepResult::ReturnNullIfNoResult>(
|
|
|
|
mozIStorageConnection& aConnection, const nsACString& aStatementString);
|
|
|
|
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
namespace detail {
|
|
|
|
|
2021-04-23 16:59:42 +03:00
|
|
|
// Given aPath of /foo/bar/baz and aRelativePath of /bar/baz, returns the
|
|
|
|
// absolute portion of aPath /foo by removing the common suffix from aPath.
|
|
|
|
nsDependentCSubstring GetTreeBase(const nsLiteralCString& aPath,
|
|
|
|
const nsLiteralCString& aRelativePath) {
|
|
|
|
MOZ_ASSERT(StringEndsWith(aPath, aRelativePath));
|
|
|
|
return Substring(aPath, 0, aPath.Length() - aRelativePath.Length());
|
|
|
|
}
|
|
|
|
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
nsDependentCSubstring GetSourceTreeBase() {
|
2021-04-23 15:02:58 +03:00
|
|
|
static constexpr auto thisSourceFileRelativePath =
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
"/dom/quota/QuotaCommon.cpp"_ns;
|
|
|
|
|
2021-04-23 16:59:42 +03:00
|
|
|
return GetTreeBase(nsLiteralCString(__FILE__), thisSourceFileRelativePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentCSubstring GetObjdirDistIncludeTreeBase(
|
|
|
|
const nsLiteralCString& aQuotaCommonHPath) {
|
|
|
|
static constexpr auto quotaCommonHSourceFileRelativePath =
|
|
|
|
"/mozilla/dom/quota/QuotaCommon.h"_ns;
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
|
2021-04-23 16:59:42 +03:00
|
|
|
return GetTreeBase(aQuotaCommonHPath, quotaCommonHSourceFileRelativePath);
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
}
|
|
|
|
|
2021-04-23 16:59:42 +03:00
|
|
|
static constexpr auto kSourceFileRelativePathMap =
|
|
|
|
std::array<std::pair<nsLiteralCString, nsLiteralCString>, 1>{
|
|
|
|
{{"mozilla/dom/LocalStorageCommon.h"_ns,
|
|
|
|
"dom/localstorage/LocalStorageCommon.h"_ns}}};
|
|
|
|
|
2021-04-23 15:02:58 +03:00
|
|
|
nsDependentCSubstring MakeSourceFileRelativePath(
|
|
|
|
const nsACString& aSourceFilePath) {
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
static constexpr auto error = "ERROR"_ns;
|
2021-04-23 16:59:42 +03:00
|
|
|
static constexpr auto mozillaRelativeBase = "mozilla/"_ns;
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
|
|
|
|
static const auto sourceTreeBase = GetSourceTreeBase();
|
|
|
|
|
2021-04-23 15:02:58 +03:00
|
|
|
if (MOZ_LIKELY(StringBeginsWith(aSourceFilePath, sourceTreeBase))) {
|
|
|
|
return Substring(aSourceFilePath, sourceTreeBase.Length() + 1);
|
2021-04-23 12:56:30 +03:00
|
|
|
}
|
|
|
|
|
2021-04-23 16:59:42 +03:00
|
|
|
// The source file could have been exported to the OBJDIR/dist/include
|
|
|
|
// directory, so we need to check that case as well.
|
|
|
|
static const auto objdirDistIncludeTreeBase = GetObjdirDistIncludeTreeBase();
|
|
|
|
|
|
|
|
if (MOZ_LIKELY(
|
|
|
|
StringBeginsWith(aSourceFilePath, objdirDistIncludeTreeBase))) {
|
|
|
|
const auto sourceFileRelativePath =
|
|
|
|
Substring(aSourceFilePath, objdirDistIncludeTreeBase.Length() + 1);
|
|
|
|
|
|
|
|
// Exported source files don't have to use the same directory structure as
|
|
|
|
// original source files. Check if we have a mapping for the exported
|
|
|
|
// source file.
|
|
|
|
const auto foundIt = std::find_if(
|
|
|
|
kSourceFileRelativePathMap.cbegin(), kSourceFileRelativePathMap.cend(),
|
|
|
|
[&sourceFileRelativePath](const auto& entry) {
|
|
|
|
return entry.first == sourceFileRelativePath;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (MOZ_UNLIKELY(foundIt != kSourceFileRelativePathMap.cend())) {
|
|
|
|
return Substring(foundIt->second, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't have a mapping for it, just remove the mozilla/ prefix
|
|
|
|
// (if there's any).
|
|
|
|
if (MOZ_LIKELY(
|
|
|
|
StringBeginsWith(sourceFileRelativePath, mozillaRelativeBase))) {
|
|
|
|
return Substring(sourceFileRelativePath, mozillaRelativeBase.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, we don't know how to transform the relative path of the
|
|
|
|
// exported source file back to the relative path of the original source
|
|
|
|
// file. This can happen when QM_TRY is used in an exported nsIFoo.h file.
|
|
|
|
// If you really need to use QM_TRY there, consider adding a new mapping
|
|
|
|
// for the exported source file.
|
|
|
|
return sourceFileRelativePath;
|
|
|
|
}
|
|
|
|
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
nsCString::const_iterator begin, end;
|
2021-04-23 15:02:58 +03:00
|
|
|
if (RFindInReadable("/"_ns, aSourceFilePath.BeginReading(begin),
|
|
|
|
aSourceFilePath.EndReading(end))) {
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
// Use the basename as a fallback, to avoid exposing any user parts of the
|
|
|
|
// path.
|
|
|
|
++begin;
|
2021-04-23 15:02:58 +03:00
|
|
|
return Substring(begin, aSourceFilePath.EndReading(end));
|
Bug 1686191 - Remove module argument from LogError. r=dom-workers-and-storage-reviewers,janv
The module argument in LogError is redundant: the module information can
already be determined from the source file path. Indeed, reporting the module
separately in the telemetry events seems unnecessary. Instead, the relative
path is now reported. This is what the analysis of the telemetry data did
reconstruct anyway.
As a consequence, it's no longer necessary to define module-specific
HandleError functions, and therefore it's also unnecessary to define
module-specific TRY macros. These are retained as simple aliases for now,
but can be removed in a later patch entirely.
This also avoids misuses of a TRY macros in the wrong module, which were
happening a few times before, resulting in confusing output or telemetry
events.
Since Bug 1686191 will add some more TRY macro variants that warn, so
simplifying the module-specific aspects will simplify that task. Furthermore,
this is in preparation of moving the TRY macro extensions to MFBT.
Differential Revision: https://phabricator.services.mozilla.com/D102767
2021-03-12 18:01:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsDependentCSubstring{static_cast<mozilla::Span<const char>>(
|
|
|
|
static_cast<const nsCString&>(error))};
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
2021-06-08 19:27:28 +03:00
|
|
|
#ifdef QM_LOG_ERROR_ENABLED
|
2021-05-27 19:33:32 +03:00
|
|
|
# ifdef QM_ERROR_STACKS_ENABLED
|
2021-05-25 12:06:10 +03:00
|
|
|
void LogError(const nsACString& aExpr, const ResultType& aResult,
|
2021-04-23 15:02:58 +03:00
|
|
|
const nsACString& aSourceFilePath, const int32_t aSourceFileLine,
|
2021-05-27 19:33:32 +03:00
|
|
|
const Severity aSeverity)
|
|
|
|
# else
|
2021-05-28 19:33:41 +03:00
|
|
|
void LogError(const nsACString& aExpr, const Maybe<nsresult> aMaybeRv,
|
2021-05-27 19:33:32 +03:00
|
|
|
const nsACString& aSourceFilePath, const int32_t aSourceFileLine,
|
|
|
|
const Severity aSeverity)
|
|
|
|
# endif
|
|
|
|
{
|
2021-05-21 12:30:29 +03:00
|
|
|
// TODO: Add MOZ_LOG support, bug 1711661.
|
|
|
|
|
2021-06-01 15:12:27 +03:00
|
|
|
// We have to ignore failures with the Verbose severity until we have support
|
|
|
|
// for MOZ_LOG.
|
|
|
|
if (aSeverity == Severity::Verbose) {
|
2021-05-21 12:30:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-08 19:27:31 +03:00
|
|
|
nsAutoCString context;
|
|
|
|
|
|
|
|
# ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED
|
|
|
|
const auto& extraInfoMap = ScopedLogExtraInfo::GetExtraInfoMap();
|
|
|
|
|
|
|
|
if (const auto contextIt = extraInfoMap.find(ScopedLogExtraInfo::kTagContext);
|
|
|
|
contextIt != extraInfoMap.cend()) {
|
|
|
|
context = *contextIt->second;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2021-06-08 19:27:31 +03:00
|
|
|
const auto severityString = [&aSeverity]() -> nsLiteralCString {
|
|
|
|
switch (aSeverity) {
|
|
|
|
case Severity::Error:
|
|
|
|
return "ERROR"_ns;
|
|
|
|
case Severity::Warning:
|
|
|
|
return "WARNING"_ns;
|
2021-08-04 12:39:55 +03:00
|
|
|
case Severity::Info:
|
|
|
|
return "INFO"_ns;
|
2021-06-08 19:27:31 +03:00
|
|
|
case Severity::Verbose:
|
|
|
|
return "VERBOSE"_ns;
|
|
|
|
}
|
|
|
|
MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Bad severity value!");
|
|
|
|
}();
|
|
|
|
|
2021-05-28 19:33:41 +03:00
|
|
|
Maybe<nsresult> maybeRv;
|
2020-09-21 13:32:55 +03:00
|
|
|
|
2021-05-25 12:06:11 +03:00
|
|
|
# ifdef QM_ERROR_STACKS_ENABLED
|
2021-05-28 19:33:41 +03:00
|
|
|
if (aResult.is<QMResult>()) {
|
|
|
|
maybeRv = Some(aResult.as<QMResult>().NSResult());
|
|
|
|
} else if (aResult.is<nsresult>()) {
|
|
|
|
maybeRv = Some(aResult.as<nsresult>());
|
|
|
|
}
|
2021-05-25 12:06:11 +03:00
|
|
|
# else
|
2021-05-28 19:33:41 +03:00
|
|
|
maybeRv = aMaybeRv;
|
2021-05-25 12:06:11 +03:00
|
|
|
# endif
|
2021-05-25 12:06:10 +03:00
|
|
|
|
2021-05-28 19:33:41 +03:00
|
|
|
nsAutoCString rvCode;
|
|
|
|
nsAutoCString rvName;
|
|
|
|
|
|
|
|
if (maybeRv) {
|
|
|
|
nsresult rv = *maybeRv;
|
|
|
|
|
|
|
|
rvCode = nsPrintfCString("0x%" PRIX32, static_cast<uint32_t>(rv));
|
|
|
|
|
|
|
|
// XXX NS_ERROR_MODULE_WIN32 should be handled in GetErrorName directly.
|
2021-05-25 12:06:10 +03:00
|
|
|
if (NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_WIN32) {
|
2021-01-22 11:39:17 +03:00
|
|
|
// XXX We could also try to get the Win32 error name here.
|
2021-05-28 19:33:41 +03:00
|
|
|
rvName = nsPrintfCString(
|
|
|
|
"NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_WIN32, 0x%" PRIX16 ")",
|
|
|
|
NS_ERROR_GET_CODE(rv));
|
2021-01-22 11:39:17 +03:00
|
|
|
} else {
|
2021-05-28 19:33:41 +03:00
|
|
|
mozilla::GetErrorName(rv, rvName);
|
2021-01-22 11:39:17 +03:00
|
|
|
}
|
2021-05-28 19:33:41 +03:00
|
|
|
}
|
2021-05-25 12:06:10 +03:00
|
|
|
|
2021-05-25 12:06:11 +03:00
|
|
|
# ifdef QM_ERROR_STACKS_ENABLED
|
2021-05-28 19:33:41 +03:00
|
|
|
nsAutoCString frameIdString;
|
|
|
|
nsAutoCString stackIdString;
|
|
|
|
nsAutoCString processIdString;
|
|
|
|
|
|
|
|
if (aResult.is<QMResult>()) {
|
|
|
|
const QMResult& result = aResult.as<QMResult>();
|
|
|
|
frameIdString = IntToCString(result.FrameId());
|
|
|
|
stackIdString = IntToCString(result.StackId());
|
|
|
|
processIdString =
|
|
|
|
IntToCString(static_cast<uint32_t>(base::GetCurrentProcId()));
|
|
|
|
}
|
2021-05-25 12:06:11 +03:00
|
|
|
# endif
|
2021-05-28 19:33:41 +03:00
|
|
|
|
|
|
|
nsAutoCString extraInfosString;
|
|
|
|
|
|
|
|
if (!rvCode.IsEmpty()) {
|
|
|
|
extraInfosString.Append(" failed with resultCode "_ns + rvCode);
|
2020-12-21 12:32:12 +03:00
|
|
|
}
|
|
|
|
|
2021-05-28 19:33:41 +03:00
|
|
|
if (!rvName.IsEmpty()) {
|
|
|
|
extraInfosString.Append(", resultName "_ns + rvName);
|
|
|
|
}
|
|
|
|
|
|
|
|
# ifdef QM_ERROR_STACKS_ENABLED
|
|
|
|
if (!frameIdString.IsEmpty()) {
|
|
|
|
extraInfosString.Append(", frameId "_ns + frameIdString);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stackIdString.IsEmpty()) {
|
|
|
|
extraInfosString.Append(", stackId "_ns + stackIdString);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!processIdString.IsEmpty()) {
|
|
|
|
extraInfosString.Append(", processId "_ns + processIdString);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
2021-06-08 19:27:30 +03:00
|
|
|
# ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED
|
2021-06-08 19:27:31 +03:00
|
|
|
for (const auto& item : extraInfoMap) {
|
2021-05-28 19:33:41 +03:00
|
|
|
extraInfosString.Append(", "_ns + nsDependentCString(item.first) + " "_ns +
|
2020-09-30 11:24:18 +03:00
|
|
|
*item.second);
|
2020-09-21 13:32:55 +03:00
|
|
|
}
|
2021-05-25 12:06:11 +03:00
|
|
|
# endif
|
2020-09-21 13:32:55 +03:00
|
|
|
|
2021-06-08 19:27:31 +03:00
|
|
|
const auto sourceFileRelativePath =
|
|
|
|
detail::MakeSourceFileRelativePath(aSourceFilePath);
|
|
|
|
|
2021-06-08 19:27:32 +03:00
|
|
|
# ifdef QM_LOG_ERROR_TO_CONSOLE_ENABLED
|
2021-03-24 15:27:53 +03:00
|
|
|
NS_DebugBreak(
|
|
|
|
NS_DEBUG_WARNING,
|
|
|
|
nsAutoCString("QM_TRY failure ("_ns + severityString + ")"_ns).get(),
|
|
|
|
(extraInfosString.IsEmpty() ? nsPromiseFlatCString(aExpr)
|
|
|
|
: static_cast<const nsCString&>(nsAutoCString(
|
|
|
|
aExpr + extraInfosString)))
|
|
|
|
.get(),
|
2021-04-23 15:02:58 +03:00
|
|
|
nsPromiseFlatCString(sourceFileRelativePath).get(), aSourceFileLine);
|
2021-05-25 12:06:11 +03:00
|
|
|
# endif
|
2020-09-08 10:40:46 +03:00
|
|
|
|
2021-06-08 19:27:32 +03:00
|
|
|
# ifdef QM_LOG_ERROR_TO_BROWSER_CONSOLE_ENABLED
|
2021-06-08 19:27:31 +03:00
|
|
|
// XXX We might want to allow reporting to the browsing console even when
|
|
|
|
// there's no context in future once we are sure that it can't spam the
|
|
|
|
// browser console or when we have special about:quotamanager for the
|
|
|
|
// reporting (instead of the browsing console).
|
|
|
|
// Another option is to keep the current check and rely on MOZ_LOG reporting
|
|
|
|
// in future once that's available.
|
|
|
|
if (!context.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIConsoleService> console =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
if (console) {
|
|
|
|
NS_ConvertUTF8toUTF16 message(
|
|
|
|
"QM_TRY failure ("_ns + severityString + ")"_ns + ": '"_ns + aExpr +
|
|
|
|
extraInfosString + "', file "_ns + sourceFileRelativePath + ":"_ns +
|
|
|
|
IntToCString(aSourceFileLine));
|
|
|
|
|
|
|
|
// The concatenation above results in a message like:
|
|
|
|
// QM_TRY failure (ERROR): 'MaybeRemoveLocalStorageArchiveTmpFile() failed
|
|
|
|
// with resultCode 0x80004005, resultName NS_ERROR_FAILURE, frameId 1,
|
|
|
|
// stackId 1, processId 53978, context Initialization::Storage', file
|
|
|
|
// dom/quota/ActorsParent.cpp:6029
|
|
|
|
|
|
|
|
console->LogStringMessage(message.get());
|
|
|
|
}
|
2020-09-08 10:40:46 +03:00
|
|
|
}
|
2021-06-08 19:27:32 +03:00
|
|
|
# endif
|
2020-12-09 23:01:07 +03:00
|
|
|
|
2021-06-08 19:27:32 +03:00
|
|
|
# ifdef QM_LOG_ERROR_TO_TELEMETRY_ENABLED
|
2021-06-08 19:27:31 +03:00
|
|
|
if (!context.IsEmpty()) {
|
2020-12-09 23:01:07 +03:00
|
|
|
// For now, we don't include aExpr in the telemetry event. It might help to
|
|
|
|
// match locations across versions, but they might be large.
|
|
|
|
auto extra = Some([&] {
|
|
|
|
auto res = CopyableTArray<EventExtraEntry>{};
|
2021-05-25 12:06:10 +03:00
|
|
|
res.SetCapacity(9);
|
2021-05-25 12:06:10 +03:00
|
|
|
|
2021-06-08 19:27:31 +03:00
|
|
|
res.AppendElement(EventExtraEntry{"context"_ns, nsCString{context}});
|
2021-05-25 12:06:10 +03:00
|
|
|
|
2021-06-08 19:27:32 +03:00
|
|
|
# ifdef QM_ERROR_STACKS_ENABLED
|
2021-05-28 19:33:41 +03:00
|
|
|
if (!frameIdString.IsEmpty()) {
|
2021-05-25 12:06:10 +03:00
|
|
|
res.AppendElement(
|
2021-05-28 19:33:41 +03:00
|
|
|
EventExtraEntry{"frame_id"_ns, nsCString{frameIdString}});
|
2021-05-25 12:06:10 +03:00
|
|
|
}
|
2020-12-09 23:01:07 +03:00
|
|
|
|
2021-05-28 19:33:41 +03:00
|
|
|
if (!processIdString.IsEmpty()) {
|
2021-05-25 12:06:10 +03:00
|
|
|
res.AppendElement(
|
2021-05-28 19:33:41 +03:00
|
|
|
EventExtraEntry{"process_id"_ns, nsCString{processIdString}});
|
2021-05-25 12:06:10 +03:00
|
|
|
}
|
2021-06-08 19:27:32 +03:00
|
|
|
# endif
|
2021-05-25 12:06:10 +03:00
|
|
|
|
2021-01-22 11:39:17 +03:00
|
|
|
if (!rvName.IsEmpty()) {
|
2020-12-21 12:32:12 +03:00
|
|
|
res.AppendElement(EventExtraEntry{"result"_ns, nsCString{rvName}});
|
|
|
|
}
|
|
|
|
|
2021-03-04 12:13:21 +03:00
|
|
|
// The sequence number is currently per-process, and we don't record the
|
|
|
|
// thread id. This is ok as long as we only record during storage
|
|
|
|
// initialization, and that happens (mostly) from a single thread. It's
|
|
|
|
// safe even if errors from multiple threads are interleaved, but the data
|
|
|
|
// will be hard to analyze then. In that case, we should record a pair of
|
|
|
|
// thread id and thread-local sequence number.
|
2021-01-07 19:18:32 +03:00
|
|
|
static Atomic<int32_t> sSequenceNumber{0};
|
|
|
|
|
|
|
|
res.AppendElement(
|
|
|
|
EventExtraEntry{"seq"_ns, IntToCString(++sSequenceNumber)});
|
|
|
|
|
2021-05-25 12:06:10 +03:00
|
|
|
res.AppendElement(EventExtraEntry{"severity"_ns, severityString});
|
|
|
|
|
|
|
|
res.AppendElement(
|
|
|
|
EventExtraEntry{"source_file"_ns, nsCString(sourceFileRelativePath)});
|
|
|
|
|
|
|
|
res.AppendElement(
|
|
|
|
EventExtraEntry{"source_line"_ns, IntToCString(aSourceFileLine)});
|
|
|
|
|
2021-06-08 19:27:32 +03:00
|
|
|
# ifdef QM_ERROR_STACKS_ENABLED
|
2021-05-28 19:33:41 +03:00
|
|
|
if (!stackIdString.IsEmpty()) {
|
2021-05-25 12:06:10 +03:00
|
|
|
res.AppendElement(
|
2021-05-28 19:33:41 +03:00
|
|
|
EventExtraEntry{"stack_id"_ns, nsCString{stackIdString}});
|
2021-05-25 12:06:10 +03:00
|
|
|
}
|
2021-06-08 19:27:32 +03:00
|
|
|
# endif
|
2021-05-25 12:06:10 +03:00
|
|
|
|
2020-12-09 23:01:07 +03:00
|
|
|
return res;
|
|
|
|
}());
|
|
|
|
|
|
|
|
Telemetry::RecordEvent(Telemetry::EventID::DomQuotaTry_Error_Step,
|
|
|
|
Nothing(), extra);
|
|
|
|
}
|
2021-06-08 19:27:32 +03:00
|
|
|
# endif
|
2020-09-08 10:40:46 +03:00
|
|
|
}
|
2021-05-25 12:06:11 +03:00
|
|
|
#endif
|
2020-09-08 10:40:46 +03:00
|
|
|
|
2020-06-25 10:16:47 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
|
2021-04-23 15:02:58 +03:00
|
|
|
const char* aSourceFilePath,
|
2021-04-23 15:02:58 +03:00
|
|
|
const int32_t aSourceFileLine) {
|
2020-06-25 10:16:47 +03:00
|
|
|
nsString leafName;
|
|
|
|
nsresult rv = aFile.GetLeafName(leafName);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return Err(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDirectory;
|
|
|
|
rv = aFile.IsDirectory(&isDirectory);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return Err(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDirectory) {
|
|
|
|
// Don't warn about OS metadata files. These files are only used in
|
|
|
|
// different platforms, but the profile can be shared across different
|
|
|
|
// operating systems, so we check it on all platforms.
|
|
|
|
if (leafName.Equals(kDSStoreFileName) ||
|
|
|
|
leafName.Equals(kDesktopFileName) ||
|
|
|
|
leafName.Equals(kDesktopIniFileName,
|
|
|
|
nsCaseInsensitiveStringComparator) ||
|
|
|
|
leafName.Equals(kThumbsDbFileName, nsCaseInsensitiveStringComparator)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't warn about files starting with ".".
|
|
|
|
if (leafName.First() == char16_t('.')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DebugBreak(
|
|
|
|
NS_DEBUG_WARNING,
|
|
|
|
nsPrintfCString("Something (%s) in the directory that doesn't belong!",
|
|
|
|
NS_ConvertUTF16toUTF8(leafName).get())
|
|
|
|
.get(),
|
2021-04-23 15:02:58 +03:00
|
|
|
nullptr, aSourceFilePath, aSourceFileLine);
|
2020-06-25 10:16:47 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom::quota
|