Skip to content

Commit

Permalink
Merge pull request #489 from cPholloway/RE-499
Browse files Browse the repository at this point in the history
Restore EA4 config files based on package prefix
  • Loading branch information
toddr authored Aug 6, 2024
2 parents b569eac + 1ba7b79 commit 223001e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
21 changes: 14 additions & 7 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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} };
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Elevate/Components/EA4.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );

Expand Down
18 changes: 13 additions & 5 deletions lib/Elevate/RPM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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} };
}

Expand Down
10 changes: 8 additions & 2 deletions t/components-ea4.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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' );
Expand Down

0 comments on commit 223001e

Please sign in to comment.