Skip to content

Commit 53ff8e0

Browse files
committed
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
1 parent 406b1cb commit 53ff8e0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

contrib/sort.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from sys import argv, exit as sys_exit, stderr
1010

1111
__doc__ = f"""\
12-
Sort the arguments of commands in profiles.
12+
Strip whitespace and sort the arguments of commands in profiles.
1313
1414
Usage: {path.basename(argv[0])} [-h] [-i] [-n] [--] [/path/to/profile ...]
1515
@@ -20,6 +20,9 @@
2020
2121
Note that this is only applicable to commands that support multiple arguments.
2222
23+
Trailing whitespace is removed in all lines (that is, not just in lines
24+
containing supported commands).
25+
2326
Options:
2427
-h Print this message.
2528
-i Edit the profile file(s) in-place (this is the default).
@@ -72,7 +75,7 @@ def check_profile(filename, overwrite):
7275
was_fixed = False
7376
fixed_profile = []
7477
for lineno, original_line in enumerate(lines, 1):
75-
line = original_line
78+
line = original_line.rstrip()
7679
if line[:12] in ("private-bin ", "private-etc ", "private-lib "):
7780
line = f"{line[:12]}{sort_alphabetical(line[12:])}"
7881
elif line[:13] in ("seccomp.drop ", "seccomp.keep "):

0 commit comments

Comments
 (0)