check_files: add on-disk size (disksize) reporting consistent with du - #459
Open
inqrphl wants to merge 8 commits into
Open
check_files: add on-disk size (disksize) reporting consistent with du#459inqrphl wants to merge 8 commits into
inqrphl wants to merge 8 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional on-disk size (
disksize) attribute tocheck_files, consistent withduon Unix and Explorer's "Size on disk" on Windows.disksize— allocated on-disk bytes per entry. On Linux/FreeBSD/macOS this isst_blocks * 512(exactly whatdu -B1reports); on Windows it is the file'sAllocationSizeviaGetFileInformationByHandleEx. Enabled only with the newadd-disk-size=trueargument, since the Windows variant requires an extra handle open per entry.total_disksize/total_diskbytes— files-only aggregate metrics, usable as thresholds.<filename> disksizemetrics — emitted when adisksizethreshold is referenced (gated like the existing<filename> sizemetric).disk_size/total_disk_size/total_disk_bytestodisksize/total_disksize/total_diskbytesto prevent collisions with per-file metrics (a file namedtotal_diskcan 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):
disksizeequalsdu -B1output for regular, empty, and sparse files<filename> disksizemetric emission and gating (add-disk-sizeoff -> no metric)total_disksizeequals the sum of matched files' disksize and is absent whenadd-disk-sizeis offmake testpasses; package builds for linux/windows/darwin/freebsd.