espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.76k stars 743 forks source link

Bangle.js: Avoid storage compaction if battery low, show status #2391

Closed gfwilliams closed 1 year ago

gfwilliams commented 1 year ago

Discussed here: https://github.com/espruino/BangleApps/issues/2865

Generally writes to storage are pretty safe and won't cause issues if the battery dies during a write, but if the storage is full then it has to be compacted. This can take a minute or more, during which a decent amount of power is used - and if the battery is very low then it could cause a shutdown during that process, which would cause storage corruption.

To make matters worse, if storage were very full and a file kept being changed, that could force storage be compacted multiple times.

So we need to:

gfwilliams commented 1 year ago

We're still not being smart about where to start compaction...

jsfGetStorageStats could maybe store the address of the first page (that's not straddled by a file) with an erased file in it, and then I believe jsfCompactInternal should be fine to start from that

gfwilliams commented 1 year ago

Turns out it wasn't that bad :)