Skip to content

fix(app): keep the SD card when a legacy sync chunk is not saved - #14899

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/app-sd-legacy-sync-clear
Sep 19, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
singhharsh1708:fix/app-sd-legacy-sync-clear

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14907

On firmware without timestamp markers, _readStorageBytesToFileLegacy catches any error from the chunk callback, sets hasError and breaks. The function then returns normally, so _syncWal sees chunksDownloaded > 0, sends the clear command (_writeToStorage(..., 1, 0)) and syncWal marks the recording synced.

The callback throws when the user cancels (Sync cancelled by user) and when addExternalWal fails to save a chunk. In both cases the chunks after the failed one are only in memory, and the card has just been wiped, so that part of the recording is gone. The marker path already propagates the same error through completer.completeError(e); this makes the legacy path rethrow so syncWal takes its existing error branch and the card is left alone. A retry downloads the file again, so chunks saved before the failure are saved a second time. That seemed better than losing the rest of the file.

testConnection lets the test drive _writeToStorage and the storage listener without the device service. test/unit/sdcard_legacy_sync_test.dart streams a file of just over two 180 s chunks. On main the cancel test and the failed-save test both fail (Expected: throws ... Actual: <Instance of 'Future<SyncLocalFilesResponse?>'>), because the sync completes and clears the card. With the fix all three pass; the third checks that a clean download still clears the card and marks the recording synced.

cd app
flutter test test/unit/sdcard_legacy_sync_test.dart   # +3: All tests passed!
bash test.sh                                           # +2370 ~5: All tests passed!
bash scripts/analyze_ratchet.sh                        # Analyzer ratchet passed.

Failure-Class: none

Review in cubic

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoped, well-tested bug/doc fix; passes confidence gate.

@kodjima33
kodjima33 merged commit cc4ebbf into BasedHardware:main Sep 19, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] fix(app): legacy SD card sync clears the card after a cancelled or failed download ($50 proposed)

2 participants