Skip to content

Commit

Permalink
Fix update_system's on_change on Redhat
Browse files Browse the repository at this point in the history
Redhat can have multiple packages installed with the same name (eg
kernels), a fact that Rex::Pkg::Base::diff_package_list is not
prepared to deal with, resulting in calling the on_change hook when
you run the update_system command, even if nothing changed in the
packages installed (see also bug #1149). This commit fixes that.
  • Loading branch information
akarelas committed Aug 26, 2024
1 parent 48e8add commit 2404749
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Revision history for Rex

[BUG FIXES]
- Return only the first found command
- Fix on_change in update_system command on Redhat

[DOCUMENTATION]

Expand Down
48 changes: 48 additions & 0 deletions lib/Rex/Pkg/Redhat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,54 @@ sub get_installed {
return @pkg;
}

sub diff_package_list {
my ( $self, $list1, $list2 ) = @_;

my @old_installed = @{$list1};
my @new_installed = @{$list2};

my @modifications;

my %old_installed;
foreach my $old_pkg (@old_installed) {
my $name = $old_pkg->{name};
my $version = "$old_pkg->{version} $old_pkg->{release}";
$old_installed{$name}{$version} = $old_pkg;
}

my %new_installed;
foreach my $new_pkg (@new_installed) {
my $name = $new_pkg->{name};
my $version = "$new_pkg->{version} $new_pkg->{release}";
if ( $old_installed{$name} and $old_installed{$name}{$version} ) {
delete $old_installed{$name}{$version};
delete $old_installed{$name} if !keys %{ $old_installed{$name} };
next;
}
$new_installed{$name}{$version} = $new_pkg;
}

foreach my $new_name ( keys %new_installed ) {
if ( $old_installed{$new_name} ) {
push @modifications, { %$_, action => 'updated' }
foreach values %{ $new_installed{$new_name} };
}
else {
push @modifications, { %$_, action => 'installed' }
foreach values %{ $new_installed{$new_name} };
}
}

foreach my $old_name ( keys %old_installed ) {
if ( !$new_installed{$old_name} ) {
push @modifications, { %$_, action => 'removed' }
foreach values %{ $old_installed{$old_name} };
}
}

return @modifications;
}

sub add_repository {
my ( $self, %data ) = @_;

Expand Down

0 comments on commit 2404749

Please sign in to comment.