зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
9adb679ac7
Коммит
e99f516901
|
@ -2697,14 +2697,33 @@ Result<uint64_t, nsresult> GetTemporaryStorageLimit(nsIFile& aStorageDir) {
|
|||
1024;
|
||||
}
|
||||
|
||||
constexpr int64_t teraByte = (1024u * 1024u * 1024u * 1024u);
|
||||
constexpr int64_t maxAllowedCapacity = 8 * teraByte;
|
||||
|
||||
// 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));
|
||||
int64_t diskCapacity = maxAllowedCapacity;
|
||||
|
||||
// Log error when default disk capacity is returned due to the error
|
||||
[&aStorageDir, &diskCapacity]() {
|
||||
QM_FAIL(aStorageDir.GetDiskCapacity(&diskCapacity));
|
||||
}();
|
||||
|
||||
MOZ_ASSERT(diskCapacity >= 0);
|
||||
|
||||
// Allow temporary storage to consume up to 50% of disk capacity.
|
||||
return diskCapacity / 2u;
|
||||
const int64_t regularCapacityLimit = diskCapacity / 2u;
|
||||
|
||||
// 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.
|
||||
int64_t capacityLimit = maxAllowedCapacity;
|
||||
|
||||
[regularCapacityLimit, &capacityLimit]() {
|
||||
QM_TRY(OkIf(regularCapacityLimit >= maxAllowedCapacity), QM_VOID);
|
||||
capacityLimit = regularCapacityLimit;
|
||||
}();
|
||||
|
||||
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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче