From db6cec2b8043a85aeec983629781f3164b5191df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sun, 11 Oct 2026 12:43:42 -0300 Subject: [PATCH] refactor(pkglist): share package-list line filtering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Share line normalization and directive filtering across the legacy text reader, its include reader and the record reader. Keep leading whitespace in legacy includes and leave each parser expansion policy unchanged. Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com> --- xCAT-server/lib/perl/xCAT/Postage.pm | 48 +++++++++++++--------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index d069a6b677..68938cfdbb 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -1819,6 +1819,21 @@ sub get_envlist return ($envlist, $pkgtext); } +sub _pkglist_line +{ + my ($line, $trim_leading) = @_; + chomp($line); + $line =~ s/\s+$//; + $line =~ s/^\s*// if $trim_leading; + return if $line =~ /^\s*$/; + return + if ($line =~ /^\s*#/ + && $line !~ /^\s*#INCLUDE:[^#^\n]+#/ + && $line !~ /^\s*#NEW_INSTALL_LIST#/ + && $line !~ /^\s*#ENV:[^#^\n]+#/); + return $line; +} + #---------------------------------------------------------------------------- =head3 get_pkglist_text @@ -1846,15 +1861,8 @@ sub get_pkglist_tex { while (readline(FILE1)) { - chomp($_); #remove newline - s/\s+$//; #remove trailing spaces - s/^\s*//; #remove leading blanks - next if /^\s*$/; #-- skip empty lines - next - if (/^\s*#/ - && !/^\s*#INCLUDE:[^#^\n]+#/ - && !/^\s*#NEW_INSTALL_LIST#/ - && !/^\s*#ENV:[^#^\n]+#/); #-- skip comments + $_ = _pkglist_line($_, 1); + next unless defined $_; if (/^@(.*)/) { #for groups that has space in name my $save = $1; @@ -1925,15 +1933,8 @@ sub pkglist_file_records open(my $fh, '<', $file) or return ("#INCLUDEBAD:cannot open pkglist file $file#"); while (my $line = <$fh>) { - chomp($line); - $line =~ s/\s+$//; - $line =~ s/^\s*//; - next if $line eq ''; - next - if ($line =~ /^#/ - && $line !~ /^#INCLUDE:[^#^\n]+#/ - && $line !~ /^#NEW_INSTALL_LIST#/ - && $line !~ /^#ENV:[^#^\n]+#/); + $line = _pkglist_line($line, 1); + next unless defined $line; if ($line =~ /^#INCLUDE:([^#^\n]+)#(.*)$/ && $depth < 20) { my ($name, $note) = ($1, $2); @@ -1974,14 +1975,9 @@ sub includefile while () { - chomp($_); #remove newline - s/\s+$//; #remove trailing spaces - next if /^\s*$/; #-- skip empty lines - next - if (/^\s*#/ - && !/^\s*#INCLUDE:[^#^\n]+#/ - && !/^\s*#NEW_INSTALL_LIST#/ - && !/^\s*#ENV:[^#^\n]+#/); #-- skip comments + # Legacy includes preserve leading whitespace, unlike root package lists. + $_ = _pkglist_line($_, 0); + next unless defined $_; if (/^@(.*)/) { #for groups that has space in name my $save = $1;