Repository navigation
Compress long log names that gzip accepts - #79
Merged
Merged
Conversation
A run directory's log can carry a name close to a filesystem's own 255-byte limit on one path component. It can still sit well inside what the reference compressor at its highest setting allows. Its own overhead is just the three bytes of the `.gz` suffix it adds. `gzipInPlace` writes its compressed bytes to a temporary name first. That way a crash or a short write cannot leave a partial archive under the final name a later run would skip. The temporary name carried the original name in full, plus a pid and a random suffix guarding it from a concurrent or a retried run. Nothing checked whether the result still fit in one path component once that suffix was added on. A name as short as 232 bytes, well under the reference tool's own limit, could report NameTooLong. The pid and the random suffix alone are already enough to keep two temporary files from colliding in the same directory. The original name is left out of the temporary one when adding it on would overflow a path component. That way a compression the final name alone would have gone on to complete does not fail. A name under the reference compressor's own 252-byte limit compresses here too, regardless of the temporary name's own overhead. One past even that limit still reports NameTooLong, exactly as the reference tool itself would refuse it. A 240-byte name is picked so the prior temporary name overflows whatever the running process's own pid happens to be. It reports NameTooLong on the parent commit, and compresses here. A full `zig build test` run reports every other case still passing.
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.
gzipInPlacecompresses through a temporary file named.<name>.<pid>.<hex>.tmp, so a log name well inside whatgzip -9accepts can push that one path component past the filesystem's 255-byte limit. A 232-byte name can already overflow it, depending on the pid;gzip -9takes names up to 252 bytes.The pid and the random suffix already keep two temporary files apart, so the original name is left out of the temporary name when including it would overflow a component.
The new test uses a 240-byte name. Without this commit it fails with the real
NameTooLongfrom the kernel'sENAMETOOLONGonopenat, with 201 of 202 tests passing. With this commitzig build testpasses 202 of 202 with no skips, on Zig 0.17.1 and Python 3.14.10.The fix is independent of the
sys.Opsfault-injection work. The same.{name}.{pid}.{hex}.tmppattern also appears insrc/atomic.zigandsrc/fsx.zigtmpName, which this change leaves alone.