mtree: escape METALOG filenames according to FreeBSD's mtree(8) / VIS_OCTAL#513
Open
tmarkettos wants to merge 2 commits into
Open
mtree: escape METALOG filenames according to FreeBSD's mtree(8) / VIS_OCTAL#513tmarkettos wants to merge 2 commits into
tmarkettos wants to merge 2 commits into
Conversation
FreeBSD's mtree file format by default uses the VIS_OCTAL format of strsvis(3) to escape non-printable characters in filenames, namely anything not within chars 33-126 or shell globs. Attempt to handle non-printable characters, including UTF-8, with an escaping function. Some basic tests are included. (A comment indicated that the VIS_CSTYLE format should be used, which encodes whitespace as \t, \n and \s. According to the FreeBSD mtree(8) manpage, that is only correct when using the 'netbsd6' flavour of mtree output. Debian's mtree(5) also specifies the VIS_OCTAL format)
arichardson
reviewed
Jul 9, 2026
| # split string into Unicode code points | ||
| c = ord(s[i]) | ||
|
|
||
| # if a non-ASCII character, convert to 3 digit octal without the 0o prefix |
Member
There was a problem hiding this comment.
Suggested change
| # if a non-ASCII character, convert to 3 digit octal without the 0o prefix | |
| # if a non-ASCII or glob character, convert to 3 digit octal without the 0o prefix |
I guess we are also escaping glob/shell special chars?
arichardson
reviewed
Jul 9, 2026
| # append an ASCII character | ||
| s_dest += s[i] | ||
|
|
||
| # return s.upper().replace(" ", "\\s") |
Member
There was a problem hiding this comment.
Suggested change
| # return s.upper().replace(" ", "\\s") |
arichardson
approved these changes
Jul 9, 2026
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.
FreeBSD's mtree file format by default uses the VIS_OCTAL format of
strsvis(3) to escape non-printable characters in filenames, namely
anything not within chars 33-126 or shell globs. Attempt to handle
non-printable characters, including UTF-8, with an escaping function.
Some basic tests are included.
(A comment indicated that the VIS_CSTYLE format should be used, which
encodes whitespace as \t, \n and \s. According to the FreeBSD
mtree(8) manpage, that is only correct when using the 'netbsd6'
flavour of mtree output. Debian's mtree(5) also specifies the
VIS_OCTAL format)