Skip to content

Commit 9a0bff6

Browse files
committed
Fat FS: If can't allocate file, attempt defragmentation and try again
1 parent 4589fbc commit 9a0bff6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Bangle.js2: Calling Bangle.getPressure() while a conversion is in progress now returns the same promise (so it will complete as soon as pressure data is ready) rather than erroring
1818
Bangle.js2: Fix 2v22 regression where `E.showMenu({test:{}})` would display 'test:undefined'
1919
Fat FS: Added `r+` file open mode (and allow w+ to read)
20+
Fat FS: If can't allocate file, attempt defragmentation and try again
2021

2122
2v26 : nRF5x: ensure TIMER1_IRQHandler doesn't always wake idle loop up (fix #1900)
2223
Puck.js: On v2.1 ensure Puck.mag behaves like other variants - just returning the last reading (avoids glitches when used with Puck.magOn)

libs/filesystem/jswrap_file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ static bool allocateJsFile(JsFile* file,FileMode mode, FileType type) {
253253
if (!parent) return false; // low memory
254254

255255
JsVar *data = jsvNewFlatStringOfLength(sizeof(JsFileData));
256+
if (!data) { // out of memory for flat string
257+
jsvDefragment(); // defrag and try again in case it was a memory fragmentation issue
258+
data = jsvNewFlatStringOfLength(sizeof(JsFileData));
259+
}
256260
if (!data) { // out of memory for flat string
257261
jsErrorFlags |= JSERR_LOW_MEMORY; // flag this up as an issue
258262
jsvUnLock(parent);

0 commit comments

Comments
 (0)