Skip to content

Commit ac2eb2b

Browse files
committed
Fix bug causing Storage not to clear unused data chunks sometimes.
1 parent 0beed6c commit ac2eb2b

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

common/Storage.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,24 @@ var Storage = (() => {
9595
for (let k of Object.keys(keys)) {
9696
let s = JSON.stringify(keys[k]);
9797
let chunksCountKey = chunksKey(k);
98-
let oldCount = await browser.storage.sync.get(chunksCountKey)[chunksCountKey] || 0;
98+
let oldCount = (await browser.storage.sync.get(chunksCountKey))[chunksCountKey] || 0;
9999
let count;
100100
if (s.length > MAX_ITEM_SIZE) {
101101
count = Math.ceil(s.length / MAX_ITEM_SIZE);
102102
let chunks = {
103103
[chunksCountKey]: count
104104
};
105-
for(let j = 0, o = 0; j < count; ++j, o += MAX_ITEM_SIZE) {
106-
chunks[`${k}/${j}`] = s.substr(o, MAX_ITEM_SIZE);
105+
for(let j = 0, offset = 0; j < count; ++j) {
106+
chunks[`${k}/${j}`] = s.substring(offset, offset += MAX_ITEM_SIZE);
107107
}
108108
await browser.storage.sync.set(chunks);
109109
keys[k] = "[CHUNKED]";
110110
} else {
111111
count = 0;
112112
removeKeys.push(chunksCountKey);
113113
}
114-
if (oldCount-- > count) {
115-
do {
116-
removeKeys.push(`${k}${oldCount}`);
117-
} while(oldCount-- > count);
114+
while (oldCount-- > count) {
115+
removeKeys.push(`${k}/${oldCount}`);
118116
}
119117
}
120118
await browser.storage.sync.remove(removeKeys);

0 commit comments

Comments
 (0)