fix(disk): stop dropping filesystems whose mount point has unusual ch… - #1063
Open
karlitschek wants to merge 1 commit into
Open
fix(disk): stop dropping filesystems whose mount point has unusual ch…#1063karlitschek wants to merge 1 commit into
karlitschek wants to merge 1 commit into
Conversation
…aracters getDiskInfo() matched the mount point against a character class — [\w\/\-\.] on Linux, [\w\/-] on FreeBSD, which did not even allow a dot. A mount point containing anything outside that set failed the whole line, and because the pattern is applied per line with preg_match_all, failing the line removed the entire filesystem from the report. No warning and no log entry: it simply was not there. A space is enough. So is a non-ASCII character, since \w does not cover one without the unicode flag, and so are brackets. On the new fixture the old Linux pattern matches 1 of 5 filesystems. `df -P` exists precisely so that output is machine readable: one record per line, no wrapping, and the mount point last. The mount point is therefore everything after the capacity column, which is what the pattern now says instead of trying to predict which characters can appear in a path. Two smaller changes in the same expression: Separators are now \s+ rather than \s*. The columns are whitespace separated, so allowing zero whitespace only worked by backtracking. Used and Capacity are now matched as \S+ rather than requiring digits and a literal percent sign. Nothing reads either of them — used is recomputed from Blocks minus Available — and `df` prints "-" in them for filesystems that do not report usage, which was another way for a row to disappear. Blocks and Available still require digits, because those are the values actually used. Verified by running the new tests against the unfixed collectors: Linux reports 1 filesystem where 5 are expected, FreeBSD 1 where 4 are expected, and both pass after the change. The existing 7-disk expectation is untouched, so the new pattern is a superset of the old one on output that already parsed. FreeBSD's getDiskInfo() had no coverage at all and gains its first. Signed-off-by: Frank Karlitschek <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
…aracters
getDiskInfo() matched the mount point against a character class — [\w/-.] on Linux, [\w/-] on FreeBSD, which did not even allow a dot. A mount point containing anything outside that set failed the whole line, and because the pattern is applied per line with preg_match_all, failing the line removed the entire filesystem from the report. No warning and no log entry: it simply was not there.
A space is enough. So is a non-ASCII character, since \w does not cover one without the unicode flag, and so are brackets. On the new fixture the old Linux pattern matches 1 of 5 filesystems.
df -Pexists precisely so that output is machine readable: one record per line, no wrapping, and the mount point last. The mount point is therefore everything after the capacity column, which is what the pattern now says instead of trying to predict which characters can appear in a path.Two smaller changes in the same expression:
Separators are now \s+ rather than \s*. The columns are whitespace separated, so allowing zero whitespace only worked by backtracking.
Used and Capacity are now matched as \S+ rather than requiring digits and a literal percent sign. Nothing reads either of them — used is recomputed from Blocks minus Available — and
dfprints "-" in them for filesystems that do not report usage, which was another way for a row to disappear. Blocks and Available still require digits, because those are the values actually used.Verified by running the new tests against the unfixed collectors: Linux reports 1 filesystem where 5 are expected, FreeBSD 1 where 4 are expected, and both pass after the change. The existing 7-disk expectation is untouched, so the new pattern is a superset of the old one on output that already parsed. FreeBSD's getDiskInfo() had no coverage at all and gains its first.
🤖 AI (if applicable)