Skip to content

Encapsulate fsBytesUsed/fsBytesTotal with read-only accessors - #5789

Merged
netmindz merged 1 commit into
wled:mainfrom
netmindz:refactor/fsbytes-accessors
Aug 8, 2026
Merged

Encapsulate fsBytesUsed/fsBytesTotal with read-only accessors#5789
netmindz merged 1 commit into
wled:mainfrom
netmindz:refactor/fsbytes-accessors

Conversation

@netmindz

@netmindz netmindz commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

Part of an ongoing pass on WLED_GLOBAL declarations (see #5777-#5788, #5774/#12 for earlier ones). fsBytesUsed/fsBytesTotal are written and read by file.cpp (via updateFSInfo()), and read-only from json.cpp (status report in serializeInfo()).

Since json.cpp never writes them, moved both to file-local static in file.cpp and exposed two by-value getters — getFsBytesUsed()/getFsBytesTotal() — instead of a mutable reference.

This is deliberately narrower in scope than earlier Tier-2 work: only applied where the external file (json.cpp) is genuinely read-only. Because the getters return by value, an accidental write from json.cpp (or any other file) is now a build error instead of a silent bug — a real, compiler-enforced improvement, not just a rename. Other Tier-2 candidates where the external file legitimately needs to write (e.g. loadLedmap, dnsServer) are being left as plain globals, since no accessor shape actually restricts a write in C++ without a real module/friend boundary — wrapping those would just relabel the same coupling.

No behavior change — purely a storage/access-pattern change.

Test plan

  • esp32dev: builds and links cleanly via pio run -e esp32dev.
  • usermods env (builds all 59 usermods): builds and links cleanly via pio run -e usermods.
  • Repo-wide grep confirms no remaining raw references to either identifier outside file.cpp.

🤖 Generated with Claude Code

fsBytesUsed/fsBytesTotal were WLED_GLOBAL, written and read by file.cpp
(via updateFSInfo()), and read-only from json.cpp (status report in
serializeInfo()). Since json.cpp never writes them, moved them to
file-local static in file.cpp and exposed two by-value getters,
getFsBytesUsed()/getFsBytesTotal(), instead of a mutable reference.

This is a real, compiler-enforced improvement, not just relabeling:
because the getters return by value, an accidental write from json.cpp
(or any other file) is now a build error instead of a silent bug -
unlike the write-needed Tier-2 cases (loadLedmap, dnsServer) that were
deliberately left as plain globals since no accessor shape actually
restricts those.

No behavior change - purely a storage/access-pattern change.

Verified:
- esp32dev builds and links cleanly via `pio run -e esp32dev`.
- usermods env (builds all 59 usermods) builds and links cleanly via
  `pio run -e usermods`.
- Repo-wide grep confirms no remaining raw references to either
  identifier outside file.cpp.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@netmindz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b7ef7e3-5e1a-48d0-bd53-294ac848eac9

📥 Commits

Reviewing files that changed from the base of the PR and between 0869ef4 and b01cb54.

📒 Files selected for processing (4)
  • wled00/fcn_declare.h
  • wled00/file.cpp
  • wled00/json.cpp
  • wled00/wled.h

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netmindz
netmindz merged commit aaa2ba0 into wled:main Aug 8, 2026
30 checks passed
@netmindz
netmindz deleted the refactor/fsbytes-accessors branch August 8, 2026 20:55
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