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).
This commit is contained in:
Kelvin M. Klann 2025-01-04 02:43:29 -03:00
parent 8c28f0e386
commit 7b47c82d6b

View file

@ -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):