Skip to content

check_files: add on-disk size (disksize) reporting consistent with du - #459

Open
inqrphl wants to merge 8 commits into
mainfrom
check-files-disk-size-support
Open

check_files: add on-disk size (disksize) reporting consistent with du#459
inqrphl wants to merge 8 commits into
mainfrom
check-files-disk-size-support

Conversation

@inqrphl

@inqrphl inqrphl commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional on-disk size (disksize) attribute to check_files, consistent with du on Unix and Explorer's "Size on disk" on Windows.

  • disksize — allocated on-disk bytes per entry. On Linux/FreeBSD/macOS this is st_blocks * 512 (exactly what du -B1 reports); on Windows it is the file's AllocationSize via GetFileInformationByHandleEx. Enabled only with the new add-disk-size=true argument, since the Windows variant requires an extra handle open per entry.
  • total_disksize / total_diskbytes — files-only aggregate metrics, usable as thresholds.
  • Per-file <filename> disksize metrics — emitted when a disksize threshold is referenced (gated like the existing <filename> size metric).
  • Naming — renamed the metrics from disk_size/total_disk_size/total_disk_bytes to disksize/total_disksize/total_diskbytes to prevent collisions with per-file metrics (a file named total_disk can no longer shadow the aggregate). Feature is unreleased, so this is a clean break with no aliases.

Tests

Added cross-platform tests (Linux/macOS/BSD + Windows):

  • disksize equals du -B1 output for regular, empty, and sparse files
  • per-file <filename> disksize metric emission and gating (add-disk-size off -> no metric)
  • graceful handling of unreadable files
  • hard links counted once per path
  • files > 4 GiB handled without overflow
  • symlink target size reporting and broken-symlink error entries
  • total_disksize equals the sum of matched files' disksize and is absent when add-disk-size is off

make test passes; package builds for linux/windows/darwin/freebsd.

Ahmet Oeztuerk and others added 7 commits August 31, 2026 12:10
uses the abstracted fileInfo struct of the golang in the linux/bsd , but has to do another windows file handle createFile operation to get its stats. golang strips the information out in its standard library.

the disksize is an optional attribute, only added when add-disk-size argument is true

total_disksize and total_diskbytes are also added as metrics
BSD/macOS du interprets -B1 as one 512 byte block, unlike GNU du where it
means 1 byte. Scale the test's du output by 512 on darwin/freebsd so the
disksize comparison stays consistent with the production st_blocks * 512.
GetFileInformationByHandleEx fails with an invalid-handle error when the
path contains 8.3 short names (ex.: C:\Users\RUNNER~1), which the CI temp
dir on windows produces. Resolve the long path form first via
GetLongPathName.

Moves the existing resolveLongPath helper out of the vhdx test into a
shared windows util so check_files can use it as well.
GetFileInformationByHandleEx returns ERROR_INVALID_HANDLE when the handle
was opened with dwDesiredAccess=0; the handle must be opened with the
FILE_READ_ATTRIBUTES access right. This is enforced on newer Windows
versions, which is why the CI runner failed while the check otherwise
reported the path fine.
golang evaluates arguments to a defer call immediately upon defining the deferred function

in getFileDiskSize, the handle was being closed directly. then it was failing the later calls uisng the same handle

now put the closing into an anonymous function without arguments, so that its closed when needed.
getfiledisksize on a directory reports the allocation for the directory itself, not including its contents
@sni
sni requested a lite review from Copilot August 31, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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