mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
build: sort.py: strip trailing whitespace in all lines
Currently the output is mangled if the last item on the line contains
trailing whitespace and is moved when sorting.
So remove trailing whitespace in all lines (that is, not just in lines
containing supported commands).
Leave leading whitespace as is for now since it could potentially be
used for indentation.
Before:
$ printf '# hello world \nprivate-bin a,b \nprivate-bin b,a \nprivate-bin a,b\n' \
>foo.profile
$ ./contrib/sort.py -n foo.profile | tr ' ' .
sort.py:.checking.1.profile(s)...
foo.profile:3:-private-bin.b,a..
foo.profile:3:+private-bin.a..,b
After:
$ printf '# hello world \nprivate-bin a,b \nprivate-bin b,a \n' \
>foo.profile
$ ./contrib/sort.py -n foo.profile | tr ' ' .
sort.py:.checking.1.profile(s)...
foo.profile:1:-#.hello.world..
foo.profile:1:+#.hello.world
foo.profile:2:-private-bin.a,b..
foo.profile:2:+private-bin.a,b
foo.profile:3:-private-bin.b,a..
foo.profile:3:+private-bin.a,b
This commit is contained in:
parent
406b1cb18e
commit
53ff8e0ad9
1 changed files with 5 additions and 2 deletions
|
|
@ -9,7 +9,7 @@ from os import path
|
|||
from sys import argv, exit as sys_exit, stderr
|
||||
|
||||
__doc__ = f"""\
|
||||
Sort the arguments of commands in profiles.
|
||||
Strip whitespace and sort the arguments of commands in profiles.
|
||||
|
||||
Usage: {path.basename(argv[0])} [-h] [-i] [-n] [--] [/path/to/profile ...]
|
||||
|
||||
|
|
@ -20,6 +20,9 @@ The following commands are supported:
|
|||
|
||||
Note that this is only applicable to commands that support multiple arguments.
|
||||
|
||||
Trailing whitespace is removed in all lines (that is, not just in lines
|
||||
containing supported commands).
|
||||
|
||||
Options:
|
||||
-h Print this message.
|
||||
-i Edit the profile file(s) in-place (this is the default).
|
||||
|
|
@ -72,7 +75,7 @@ def check_profile(filename, overwrite):
|
|||
was_fixed = False
|
||||
fixed_profile = []
|
||||
for lineno, original_line in enumerate(lines, 1):
|
||||
line = original_line
|
||||
line = original_line.rstrip()
|
||||
if line[:12] in ("private-bin ", "private-etc ", "private-lib "):
|
||||
line = f"{line[:12]}{sort_alphabetical(line[12:])}"
|
||||
elif line[:13] in ("seccomp.drop ", "seccomp.keep "):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue