Skip to content

Commit

Permalink
Fix ability to overwrite overquota'ed cloud storage
Browse files Browse the repository at this point in the history
This commit fixes deleting all entries when cloud
storage usage is beyond allowed limit.

The issue would prevent pushing new data well within
quota limit because the old data beyond limit was
never removed in the first place.
  • Loading branch information
gorhill committed Aug 24, 2020
1 parent 63e2261 commit 6284eca
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1522,8 +1522,6 @@ vAPI.cloud = (( ) => {
maxChunkSize = evalMaxChunkSize();
}, { once: true });

const maxStorageSize = QUOTA_BYTES;

const options = {
defaultDeviceName: window.navigator.platform,
deviceName: undefined,
Expand Down Expand Up @@ -1562,13 +1560,7 @@ vAPI.cloud = (( ) => {
const deleteChunks = async function(datakey, start) {
const keys = [];

// No point in deleting more than:
// - The max number of chunks per item
// - The max number of chunks per storage limit
const n = Math.min(
maxChunkCountPerItem,
Math.ceil(maxStorageSize / maxChunkSize)
);
const n = await getCoarseChunkCount(datakey);
for ( let i = start; i < n; i++ ) {
keys.push(datakey + i.toString());
}
Expand Down Expand Up @@ -1612,7 +1604,7 @@ vAPI.cloud = (( ) => {
// this will free storage space which could otherwise cause the push
// operation to fail.
try {
await deleteChunks(datakey, chunkCount);
await deleteChunks(datakey, chunkCount + 1);
} catch (reason) {
}

Expand Down

0 comments on commit 6284eca

Please sign in to comment.