Add comment to explicit "used" calculation for disk usage API (#6340)

* Add explicit used calculation for disk usage API

Added explicit calculation for used disk space along with a comment
to clarify the reasoning behind the calculation method.

* Address review feedback
This commit is contained in:
Stefan Agner
2025-11-25 10:00:46 +01:00
committed by GitHub
parent 7244e447ab
commit 032fa4cdc4

View File

@@ -347,6 +347,10 @@ class APIHost(CoreSysAttributes):
disk.disk_usage, self.sys_config.path_supervisor
)
# Calculate used by subtracting free makes sure we include reserved space
# in used space reporting.
used = total - free
known_paths = await self.sys_run_in_executor(
disk.get_dir_sizes,
{
@@ -365,13 +369,12 @@ class APIHost(CoreSysAttributes):
"id": "root",
"label": "Root",
"total_bytes": total,
"used_bytes": total - free,
"used_bytes": used,
"children": [
{
"id": "system",
"label": "System",
"used_bytes": total
- free
"used_bytes": used
- sum(path["used_bytes"] for path in known_paths),
},
*known_paths,