From 7b47c82d6bd8fe2c9b1fc95fda0c75a6fee0dd5a Mon Sep 17 00:00:00 2001 From: "Kelvin M. Klann" Date: Sat, 4 Jan 2025 02:43:29 -0300 Subject: [PATCH] build: sort.py: ignore empty files Currently it adds a newline to empty files. Before: $ : >foo.profile $ contrib/sort.py foo.profile sort.py: checking 1 profile(s)... foo.profile:(fixed whitespace) [ Fixed ] foo.profile $ od -A n -t x1 foo.profile 0a After: $ : >foo.profile $ contrib/sort.py foo.profile sort.py: checking 1 profile(s)... $ This amends commit c222b7f69 ("build: sort.py: fix whitespace in entire profile (#6593)", 2024-12-28). --- contrib/sort.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/sort.py b/contrib/sort.py index 361f8a9b94..999f429908 100755 --- a/contrib/sort.py +++ b/contrib/sort.py @@ -76,7 +76,11 @@ def sort_protocol(original_protocols): def check_profile(filename, overwrite): with open(filename, "r+") as profile: - lines = profile.read().split("\n") + original_profile_str = profile.read() + if not original_profile_str: + return + + lines = original_profile_str.split("\n") was_fixed = False fixed_profile = [] for lineno, original_line in enumerate(lines, 1):