diff --git a/ChangeLog b/ChangeLog index f341bb71e..469acb920 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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] diff --git a/lib/Rex/Pkg/Redhat.pm b/lib/Rex/Pkg/Redhat.pm index 506f6f3b9..15c06f68c 100644 --- a/lib/Rex/Pkg/Redhat.pm +++ b/lib/Rex/Pkg/Redhat.pm @@ -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 ) = @_;