diff --git a/elevate-cpanel b/elevate-cpanel index 273c9e3d..c3ba6ef6 100755 --- a/elevate-cpanel +++ b/elevate-cpanel @@ -3441,8 +3441,7 @@ EOS Elevate::StageFile::remove_from_stage_file('ea4_config_files'); - my $ea4_regex = qr/^EA4(:?-c7)?/a; - my $ea4_config_files = $self->rpm->get_config_files_for_repo($ea4_regex); + my $ea4_config_files = $self->rpm->get_config_files_for_pkg_prefix('ea-'); Elevate::StageFile::update_stage_file( { ea4_config_files => $ea4_config_files } ); @@ -7226,10 +7225,11 @@ EOS die q[Missing cpev]; } - sub get_config_files_for_repo ( $self, $repo ) { + sub get_config_files_for_pkg_prefix ( $self, $prefix ) { - my @installed = cpev::get_installed_rpms_in_repo($repo); - my $config_files = $self->_get_config_files( \@installed ); + my @installed_rpms = $self->get_installed_rpms(q[%{NAME}\n]); + my @ea_rpms = grep { $_ =~ qr/^\Q$prefix\E/ } @installed_rpms; + my $config_files = $self->_get_config_files( \@ea_rpms ); return $config_files; } @@ -7288,8 +7288,15 @@ EOS return; } - sub get_installed_rpms ($self) { - my $out = $self->cpev->ssystem_capture_output( $rpm, '-qa' ); + sub get_installed_rpms ( $self, $format = undef ) { + my @args = qw{-qa}; + + if ($format) { + push @args, '--queryformat'; + push @args, $format; + } + + my $out = $self->cpev->ssystem_capture_output( $rpm, @args ); return @{ $out->{stdout} }; } diff --git a/lib/Elevate/Components/EA4.pm b/lib/Elevate/Components/EA4.pm index 9d557e88..1bef22df 100644 --- a/lib/Elevate/Components/EA4.pm +++ b/lib/Elevate/Components/EA4.pm @@ -118,8 +118,7 @@ sub _backup_config_files ($self) { Elevate::StageFile::remove_from_stage_file('ea4_config_files'); - my $ea4_regex = qr/^EA4(:?-c7)?/a; - my $ea4_config_files = $self->rpm->get_config_files_for_repo($ea4_regex); + my $ea4_config_files = $self->rpm->get_config_files_for_pkg_prefix('ea-'); Elevate::StageFile::update_stage_file( { ea4_config_files => $ea4_config_files } ); diff --git a/lib/Elevate/RPM.pm b/lib/Elevate/RPM.pm index e8eae60a..1fc4fd33 100644 --- a/lib/Elevate/RPM.pm +++ b/lib/Elevate/RPM.pm @@ -24,10 +24,11 @@ sub _build_cpev { die q[Missing cpev]; } -sub get_config_files_for_repo ( $self, $repo ) { +sub get_config_files_for_pkg_prefix ( $self, $prefix ) { - my @installed = cpev::get_installed_rpms_in_repo($repo); - my $config_files = $self->_get_config_files( \@installed ); + my @installed_rpms = $self->get_installed_rpms(q[%{NAME}\n]); + my @ea_rpms = grep { $_ =~ qr/^\Q$prefix\E/ } @installed_rpms; + my $config_files = $self->_get_config_files( \@ea_rpms ); return $config_files; } @@ -92,8 +93,15 @@ sub remove_no_dependencies_and_justdb ( $self, $pkg ) { return; } -sub get_installed_rpms ($self) { - my $out = $self->cpev->ssystem_capture_output( $rpm, '-qa' ); +sub get_installed_rpms ( $self, $format = undef ) { + my @args = qw{-qa}; + + if ($format) { + push @args, '--queryformat'; + push @args, $format; + } + + my $out = $self->cpev->ssystem_capture_output( $rpm, @args ); return @{ $out->{stdout} }; } diff --git a/t/components-ea4.t b/t/components-ea4.t index 75eb392e..f6b1d6c3 100644 --- a/t/components-ea4.t +++ b/t/components-ea4.t @@ -455,8 +455,7 @@ sub test_backup_and_restore_config_files : Test(10) ($self) { my $cpev_mock = Test::MockModule->new('cpev'); $cpev_mock->redefine( - get_installed_rpms_in_repo => sub { return ( 'ea-foo', 'ea-bar', 'ea-nginx' ) }, - ssystem_capture_output => sub ( $, @args ) { + ssystem_capture_output => sub ( $, @args ) { my $pkg = pop @args; my $config_file = $pkg =~ /foo$/ ? '/tmp/foo.conf' : '/tmp/bar.conf'; my $ret = { @@ -467,6 +466,13 @@ sub test_backup_and_restore_config_files : Test(10) ($self) { }, ); + my $mock_rpm = Test::MockModule->new('Elevate::RPM'); + $mock_rpm->redefine( + get_installed_rpms => sub { + return ( 'ea-foo', 'ea-bar', 'ea-nginx', 'not-an-ea-package' ); + }, + ); + my $ea4 = cpev->new->component('EA4'); is( $ea4->_backup_config_files(), undef, '_backup_config_files() successfully completes' );