fix: detect save changes when emulator freezes mtime#12
Merged
Conversation
- Add computeMd5Hex() helper using mbedtls_md5 (already linked via mbedcrypto) that hashes a local file into a lowercase hex string - In performSync(), fall back to an MD5 content comparison when localMtime is unchanged but a driveMd5 from the last sync is known - Fixes GBA (and other) emulators that write save data without ever updating the FAT32 modification timestamp, causing saves to be silently skipped on every subsequent sync
There was a problem hiding this comment.
Pull request overview
Adds an MD5-based fallback to detect local file changes when the FAT32 mtime is stale (notably for GBA emulator .sav files), so saves are no longer silently skipped.
Changes:
- New
computeMd5Hex()helper streams a local file throughmbedtls_md5and returns a lowercase hex digest. performSync()recomputes the local MD5 when mtime is unchanged but a previousdriveMd5exists, marking the file as locally changed if the digests differ.- Minor whitespace/alignment tweak in
ManifestEntry.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| source/main.cpp | Adds computeMd5Hex helper and integrates an MD5 fallback path into performSync for frozen-mtime detection. |
| source/modules/manifest.h | Cosmetic comment alignment for localMtime. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Problem
GBA (and some other) emulators write save data directly to the
.savfile without updating the FAT32 modification timestamp. BecauselocalChangedwas computed solely fromst_mtime, the file always appeared unchanged and was silently skipped on every sync — even after the user saved in-game.Confirmed via FTP: the save file's mtime had not changed in ~2 years despite active saves. File size is also useless as a signal since GBA saves are fixed-size memory dumps.
Fix
computeMd5Hex()helper (source/main.cpp) that streams a local file throughmbedtls_md5and returns a lowercase hex digest.mbedcryptois already linked.performSync(), whenlocalMtimeis unchanged but adriveMd5is recorded in the manifest (i.e. the file has been synced at least once), compute the local MD5 and compare. If it differs, treat the file as locally changed and upload it.This is a fallback-only path — files whose mtime changes normally are unaffected. The MD5 check only runs when mtime is frozen.