From 8e848894fa2543f2a893194d4debe13a55df00cc Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Tue, 7 Jul 2026 09:33:08 +0200 Subject: [PATCH] feat(firmware): add RECLONE_EACH_BOOT toggle to git_sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Debug/recovery knob (ships false): when true, wipe /spiflash/repo and re-clone every boot instead of opening the persistent clone. Doubles as the validation harness for the FAT read-only-delete fix — the wipe deletes libgit2-created objects, which only succeeds once they are writable. --- firmware/src/bin/git_sync.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/firmware/src/bin/git_sync.rs b/firmware/src/bin/git_sync.rs index 7ce6335..5635fda 100644 --- a/firmware/src/bin/git_sync.rs +++ b/firmware/src/bin/git_sync.rs @@ -76,6 +76,15 @@ const REPO_DIR: &str = "/spiflash/repo"; /// The tracked file we append to. Stands in for the editor's note file(s). const NOTES_FILE: &str = "notes.md"; +/// Debug/recovery + the read-only-delete test knob: when true, wipe REPO_DIR and +/// re-clone from scratch every boot instead of opening the existing clone. +/// Deleting the existing clone's objects only succeeds with the esp_stubs +/// p_open/p_creat fix (libgit2 objects are otherwise mode 0444 → AM_RDO → +/// un-deletable on FAT). Ships **false** — the product opens the persistent +/// clone and fast-forwards; flip true to validate the RO-delete fix or to force +/// a clean re-clone. +const RECLONE_EACH_BOOT: bool = false; + /// GitHub's root CAs, embedded so the push can verify the server's TLS chain. /// Shared with `git_push` (same file). Written to FAT and handed to libgit2 via /// GIT_OPT_SET_SSL_CERT_LOCATIONS. @@ -235,6 +244,11 @@ fn publish() -> Result { /// whether a clone happened. Clone carries the auth + cert callbacks (the remote /// may be private, and the TLS chain is verified either way). fn open_or_clone() -> Result<(Repository, bool)> { + if RECLONE_EACH_BOOT && Path::new(REPO_DIR).exists() { + log::warn!("RECLONE_EACH_BOOT — removing {REPO_DIR} to re-clone from scratch"); + fs::remove_dir_all(REPO_DIR) + .context("RECLONE_EACH_BOOT wipe — deletes libgit2 objects, needs the RO-delete fix")?; + } match Repository::open(REPO_DIR) { Ok(repo) => { log::info!("opened existing clone at {REPO_DIR}");