Bug 1581067 - P5 - Only remove the temporary body files & body directories when it's in the initializing stage; r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D47770

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Tung 2019-10-02 10:38:55 +00:00
Родитель 30f7de3114
Коммит 9e63838884
3 изменённых файлов: 28 добавлений и 17 удалений

33
dom/cache/FileUtils.cpp поставляемый
Просмотреть файл

@ -389,7 +389,9 @@ nsresult BodyDeleteFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
fileDeleted = false;
return NS_OK;
};
rv = BodyTraverseFiles(aQuotaInfo, bodyDir, removeFileForId);
rv = BodyTraverseFiles(aQuotaInfo, bodyDir, removeFileForId,
/* aCanRemoveFiles */ false,
/* aTrackQuota */ true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -559,7 +561,9 @@ nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
fileDeleted = false;
return NS_OK;
};
rv = BodyTraverseFiles(aQuotaInfo, subdir, removeOrphanedFiles);
rv = BodyTraverseFiles(aQuotaInfo, subdir, removeOrphanedFiles,
/* aCanRemoveFiles */ true,
/* aTrackQuota */ true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -574,7 +578,7 @@ nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
template <typename Func>
nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBodyDir,
const Func& aHandleFileFunc,
const bool aTrackQuota) {
const bool aCanRemoveFiles, const bool aTrackQuota) {
MOZ_DIAGNOSTIC_ASSERT(aBodyDir);
nsresult rv;
@ -625,17 +629,16 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBodyDir,
// Delete all tmp files regardless of known bodies. These are all
// considered orphans.
if (StringEndsWith(leafName, NS_LITERAL_CSTRING(".tmp"))) {
DebugOnly<nsresult> result = RemoveNsIFile(aQuotaInfo, file, aTrackQuota);
MOZ_ASSERT(NS_SUCCEEDED(result));
continue;
}
nsCString suffix(NS_LITERAL_CSTRING(".final"));
// Otherwise, it must be a .final file. If its not, then try to remove it
// and move on
if (NS_WARN_IF(!StringEndsWith(leafName, suffix) ||
leafName.Length() != NSID_LENGTH - 1 + suffix.Length())) {
if (aCanRemoveFiles) {
DebugOnly<nsresult> result =
RemoveNsIFile(aQuotaInfo, file, aTrackQuota);
MOZ_ASSERT(NS_SUCCEEDED(result));
continue;
}
} else if (NS_WARN_IF(
!StringEndsWith(leafName, NS_LITERAL_CSTRING(".final")))) {
// Otherwise, it must be a .final file. If its not, then try to remove it
// and move on
DebugOnly<nsresult> result =
RemoveNsIFile(aQuotaInfo, file, /* aTrackQuota */ false);
MOZ_ASSERT(NS_SUCCEEDED(result));
@ -657,7 +660,7 @@ nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBodyDir,
return rv;
}
if (isEmpty) {
if (isEmpty && aCanRemoveFiles) {
DebugOnly<nsresult> result =
RemoveNsIFileRecursively(aQuotaInfo, aBodyDir, /* aTrackQuota */ false);
MOZ_ASSERT(NS_SUCCEEDED(result));

6
dom/cache/FileUtils.h поставляемый
Просмотреть файл

@ -58,9 +58,15 @@ nsresult BodyDeleteFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
nsresult BodyDeleteOrphanedFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBaseDir,
nsTArray<nsID>& aKnownBodyIdList);
// If aCanRemoveFiles is true, that means we are safe to touch the files which
// can be accessed in other threads.
// If it's not, that means we cannot remove the files which are possible to
// created by other threads. Note that if the files are not expected, we should
// be safe to remove them in any case.
template <typename Func>
nsresult BodyTraverseFiles(const QuotaInfo& aQuotaInfo, nsIFile* aBodyDir,
const Func& aHandleFileFunc,
const bool aCanRemoveFiles,
const bool aTrackQuota = true);
nsresult CreateMarkerFile(const QuotaInfo& aQuotaInfo);

6
dom/cache/QuotaClient.cpp поставляемый
Просмотреть файл

@ -37,7 +37,7 @@ using mozilla::dom::quota::UsageInfo;
using mozilla::ipc::AssertIsOnBackgroundThread;
static nsresult GetBodyUsage(nsIFile* aMorgueDir, const Atomic<bool>& aCanceled,
UsageInfo* aUsageInfo) {
UsageInfo* aUsageInfo, const bool aInitializing) {
AssertIsOnIOThread();
nsCOMPtr<nsIDirectoryEnumerator> entries;
@ -88,6 +88,8 @@ static nsresult GetBodyUsage(nsIFile* aMorgueDir, const Atomic<bool>& aCanceled,
return NS_OK;
};
rv = mozilla::dom::cache::BodyTraverseFiles(dummy, bodyDir, getUsage,
/* aCanRemoveFiles */
aInitializing,
/* aTrackQuota */ false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -474,7 +476,7 @@ class CacheQuotaClient final : public Client {
if (isDir) {
if (leafName.EqualsLiteral("morgue")) {
rv = GetBodyUsage(file, aCanceled, aUsageInfo);
rv = GetBodyUsage(file, aCanceled, aUsageInfo, aInitializing);
if (NS_WARN_IF(NS_FAILED(rv))) {
if (rv != NS_ERROR_ABORT) {
REPORT_TELEMETRY_ERR_IN_INIT(aInitializing, kQuotaExternalError,