fix(storage): only judge the profile-tree root absent

sdProfileTreeContainsFile() re-stat'ed every recursive child with
SD.exists() before opening it. The child came straight from
openNextFile(), so it provably exists; the check can only ever produce a
false negative, and false is the single verdict that lets a residual
foreign subtree read as empty and the card get claimed. Every other
uncertainty in this function already fails closed.

Keep the check at the root, where "/meshcomod is absent" genuinely means
there is nothing to conflict with, and let the open() fail-closed path
govern below it.

Signed-off-by: Pixel Perfect <me@pixp.cc>
This commit is contained in:
Pixel Perfect committed 2026-08-05 17:55:49 -07:00
1 parent 63af1a5270
commit 19fe554bc8
1 file changed
+6 -1
+6 -1
View File
@@ -237,7 +237,12 @@ static constexpr const char* kSdMigrationOwner = "/meshcomod/.spiffs-migration-v
static constexpr const char* kSdMigrationOwnerTmp = "/meshcomod/.spiffs-migration-v1.owner.tmp";
static bool sdProfileTreeContainsFile(const char* path, uint8_t depth = 0) {
if (!SD.exists(path)) return false;
// Only the root may be judged absent. A recursive child came straight from
// openNextFile(), so it provably exists and re-stat'ing it can only produce a
// false negative — which would be the one verdict that lets a foreign
// residual subtree read as empty and get claimed. Below the root, let the
// open() fail-closed path govern instead.
if (depth == 0 && !SD.exists(path)) return false;
if (depth >= 8) return true; // unexpected/deep content is not safe to adopt
File dir = SD.open(path, FILE_READ);
if (!dir) return true; // unreadable content is not an empty profile