Bug 1746894 - Handle GetTemporaryStorageLimit failures with upper limit. r=dom-storage-reviewers,jesup

Differential Revision: https://phabricator.services.mozilla.com/D140990
This commit is contained in:
Jari Jalkanen 2022-10-24 15:15:33 +00:00
Родитель 42c8e9b776
Коммит cc27d88b5d
3 изменённых файлов: 31 добавлений и 16 удалений

Просмотреть файл

@ -2697,14 +2697,28 @@ Result<uint64_t, nsresult> GetTemporaryStorageLimit(nsIFile& aStorageDir) {
1024;
}
// Check for disk capacity of user's device on which storage directory lives.
QM_TRY_INSPECT(const int64_t& diskCapacity,
MOZ_TO_RESULT_INVOKE_MEMBER(aStorageDir, GetDiskCapacity));
constexpr int64_t teraByte = (1024LL * 1024LL * 1024LL * 1024LL);
constexpr int64_t maxAllowedCapacity = 8LL * teraByte;
MOZ_ASSERT(diskCapacity >= 0);
// Check for disk capacity of user's device on which storage directory lives.
int64_t diskCapacity = maxAllowedCapacity;
// Log error when default disk capacity is returned due to the error
QM_WARNONLY_TRY(MOZ_TO_RESULT(aStorageDir.GetDiskCapacity(&diskCapacity)));
MOZ_ASSERT(diskCapacity >= 0LL);
// Allow temporary storage to consume up to 50% of disk capacity.
return diskCapacity / 2u;
int64_t capacityLimit = diskCapacity / 2LL;
// If the disk capacity reported by the operating system is very
// large and potentially incorrect due to hardware issues,
// a hardcoded limit is supplied instead.
QM_WARNONLY_TRY(
OkIf(capacityLimit < maxAllowedCapacity),
([&capacityLimit](const auto&) { capacityLimit = maxAllowedCapacity; }));
return capacityLimit;
}
bool IsOriginUnaccessed(const FullOriginMetadata& aFullOriginMetadata,

Просмотреть файл

@ -1492,14 +1492,11 @@ nsresult nsLocalFile::GetDiskInfo(StatInfoFunc&& aStatInfoFunc,
checkedResult = std::forward<StatInfoFunc>(aStatInfoFunc)(fs_buf);
if (!checkedResult.isValid()) {
return NS_ERROR_FAILURE;
return NS_ERROR_CANNOT_CONVERT_DATA;
}
*aResult = checkedResult.value();
# ifdef DEBUG_DISK_SPACE
printf("DiskInfo: %lu bytes\n", *aResult);
# endif
// If we return an error, *aValue will not be modified.
int64_t tentativeResult = checkedResult.value();
# if defined(USE_LINUX_QUOTACTL)
@ -1523,15 +1520,21 @@ nsresult nsLocalFile::GetDiskInfo(StatInfoFunc&& aStatInfoFunc,
&& dq.dqb_bhardlimit) {
checkedResult = std::forward<QuotaInfoFunc>(aQuotaInfoFunc)(dq);
if (!checkedResult.isValid()) {
return NS_ERROR_FAILURE;
return NS_ERROR_CANNOT_CONVERT_DATA;
}
if (checkedResult.value() < *aResult) {
*aResult = checkedResult.value();
if (checkedResult.value() < tentativeResult) {
tentativeResult = checkedResult.value();
}
}
# endif
# ifdef DEBUG_DISK_SPACE
printf("DiskInfo: %lu bytes\n", tentativeResult);
# endif
*aResult = tentativeResult;
return NS_OK;
#else

Просмотреть файл

@ -2734,8 +2734,6 @@ nsLocalFile::GetDiskCapacity(int64_t* aDiskCapacity) {
return NS_ERROR_INVALID_ARG;
}
*aDiskCapacity = 0;
nsresult rv = ResolveAndStat();
if (NS_FAILED(rv)) {
return rv;