fix(xmodem): truncate file on open instead of appending#10143
fix(xmodem): truncate file on open instead of appending#10143benallfree wants to merge 9 commits intomeshtastic:developfrom
Conversation
FILE_O_WRITE on nRF52 (Adafruit LittleFS) appends to existing files rather than truncating. Remove the file before opening for write so repeated XModem uploads always produce the correct file size. Made-with: Cursor
There was a problem hiding this comment.
Pull request overview
This PR updates the XModem receive path to ensure a new transfer to an existing filename overwrites prior contents (truncate semantics) rather than appending, aligning expected file-transfer behavior across supported filesystems/platforms.
Changes:
- Delete any pre-existing destination file before opening for write in the XModem receive flow.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…rmware into fix/xmodem-truncate-on-write
|
@thebentern Copilot brought up a good point about preserving atomicity by writing to a tmp file and then doing a rename. I updated the PR to reflect that. |
There was a problem hiding this comment.
Pull request overview
This PR updates the XModem receive flow to avoid unintended appending when receiving a file to an existing path by writing to a temporary file and committing it at end-of-transmission.
Changes:
- Add receive state (
recvCommitPending) and a receive temp path buffer (recvTmpPath) to support temp-file based receives. - On receive start, build
{filename}.tmp, remove any pre-existing temp file, and write incoming blocks to the temp file. - On EOT/CAN, close and either commit via
renameFile()(with retry support) or delete the temp file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/xmodem.h | Adds new receive state and temp path storage to support safe receive/commit behavior. |
| src/xmodem.cpp | Implements temp-file receive + EOT commit (rename) and cancel cleanup; improves filename copying/termination. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@thebentern Sorry for the delay, for some reason I am not getting GH notifications on this PR. |
This PR fixes what I perceive is a bug in the XModem module: subsequent file writes to the same path append data rather than truncating.
🤝 Attestations