Skip to content

fix: detect save changes when emulator freezes mtime#12

Merged
michvllni merged 1 commit into
masterfrom
fix/hash-fallback
May 29, 2026
Merged

fix: detect save changes when emulator freezes mtime#12
michvllni merged 1 commit into
masterfrom
fix/hash-fallback

Conversation

@michvllni

Copy link
Copy Markdown
Collaborator

Problem

GBA (and some other) emulators write save data directly to the .sav file without updating the FAT32 modification timestamp. Because localChanged was computed solely from st_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

  • Add computeMd5Hex() helper (source/main.cpp) that streams a local file through mbedtls_md5 and returns a lowercase hex digest. mbedcrypto is already linked.
  • In performSync(), when localMtime is unchanged but a driveMd5 is 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.

- 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 through mbedtls_md5 and returns a lowercase hex digest.
  • performSync() recomputes the local MD5 when mtime is unchanged but a previous driveMd5 exists, 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.

@michvllni michvllni merged commit fb63b91 into master May 29, 2026
5 checks passed
@michvllni michvllni deleted the fix/hash-fallback branch May 29, 2026 13:18
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.

2 participants