Repository navigation
host: open FILE_O_WRITE as LittleFS does, without truncating - #35
Merged
Merged
Conversation
FILE_O_WRITE was "wb", which empties the file and gives a write-only handle. On nRF52, Adafruit_LittleFS opens it read-write, created if missing, not truncated, positioned at the end, and MeshCore relies on that in two places: DataStore::putBlobByKey reads the advert store and overwrites one record in place, and openAppend in the repeater and room server adds to the packet log. On the host the companion kept only the last advert heard, so sharing or exporting any other contact failed, and the packet log held one line. filesystem_test.cpp pins the behaviour; it fails four checks without this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes, and why
FILE_O_WRITEwas"wb", which empties the file and gives a write-only handle. On nRF52, Adafruit_LittleFS opens it read-write, created if missing, not truncated, positioned at the end. MeshCore relies on that in two places:DataStore::putBlobByKeyreads the advert store and overwrites one record in place;openAppend, in the repeater and room server, adds to the packet log.From outside, the symptom was a companion that could share or export only the last contact it heard (ERR 3 or ERR 2 for any other), and a packet log that held one line. The advert store shrank from its pre-allocated 3,600 bytes to one 180-byte record after the first advert.
open()now opensFILE_O_WRITEwith"r+b", falling back to"w+b"when the file doesn't exist, then seeks to the end."a+b"would not do, because it forces every write to the end and breaksputBlobByKey's seek-and-overwrite. Writers that remove the file first, which is every otherFILE_O_WRITEuser in MeshCore v1.18.0, behave as before.Verification
variants/host/filesystem_test.cpp, new, run as its header says. Without the change it prints four FAILs (an existing file keeps its contents; a write with no seek lands at the end; the handle reads; a record is overwritten in place) and exits 1. With it, it printsok. Likestreaming_test.cpp, it is run by hand: the workflows don't build it.build.shat companion-v1.18.0 with this change, and run under MeshBench v0.4.1: a companion beside two repeaters, driven by meshcore_py 2.3.19.adv_blobswas 180 B after the first advert, sharing the first-heard contact gave01 03, exporting it gave01 02, and the repeater'spacket_logafterlog startheld 1 line.adv_blobsstayed 3,600 B with both records, share and export answered OK and the advert, and the log held 13 lines.The change was made against companion-v1.18.0 and applies unchanged to main.
Reported in MeshBench/meshbench#808, which has the reproduction.