From 12504dc2c4896aa4eae90f372460f795029450da Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Thu, 26 Nov 2020 08:57:11 +0100 Subject: [PATCH] fix: Fix Snap inventory on linux --- Changes | 1 + .../Task/Inventory/Generic/Softwares/Snap.pm | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 3953cae3bf..18eb66e44e 100644 --- a/Changes +++ b/Changes @@ -26,6 +26,7 @@ inventory: * Fix #540: Added powersupplies support on MacOS * Fix #797: Fix ASM storage inventory * Better canonical manufacturer reporting +* Fix Snap software inventory support with long summary on a package * Added PartNumber API to enhanced inventory memory and controllers support: * Elpida, Hynix, Micron & Samsung memory partnumbers * Dell controller partnumbers diff --git a/lib/FusionInventory/Agent/Task/Inventory/Generic/Softwares/Snap.pm b/lib/FusionInventory/Agent/Task/Inventory/Generic/Softwares/Snap.pm index cba9f7e6cc..b049f7ae46 100644 --- a/lib/FusionInventory/Agent/Task/Inventory/Generic/Softwares/Snap.pm +++ b/lib/FusionInventory/Agent/Task/Inventory/Generic/Softwares/Snap.pm @@ -5,6 +5,7 @@ use warnings; use parent 'FusionInventory::Agent::Task::Inventory::Module'; +use English qw(-no_match_vars); use File::stat; use YAML::Tiny; @@ -55,7 +56,7 @@ sub _getPackagesList { next if $infos[0] eq 'Name' && $infos[1] eq 'Version'; # Skip base and snapd - next if $infos[5] && $infos[5] =~ /^base|snapd$/; + next if $infos[5] && $infos[5] =~ /^base|core|snapd$/; my $snap = { NAME => $infos[0], @@ -73,7 +74,7 @@ sub _getPackagesList { ); } - push @packages, $snap, + push @packages, $snap; } close $handle; @@ -83,15 +84,25 @@ sub _getPackagesList { sub _getPackagesInfo { my (%params) = @_; + # snap info command may wrongly output some long infos + local $ENV{COLUMNS} = 100; + my $snap = delete $params{snap}; my $lines = getAllLines(%params) or return; - my $yaml = YAML::Tiny->read_string($lines); - my $infos = $yaml->[0] - or return; + my ($yaml, $infos); + eval { + $yaml = YAML::Tiny->read_string($lines); + $infos = $yaml->[0]; + }; + + if ($EVAL_ERROR && $params{logger}) { + $params{logger}->warning("Wrong $snap->{NAME} snap info output: $EVAL_ERROR"); + $params{logger}->info("Please report snap info output:\n$lines"); + } - return unless $infos->{name}; + return unless $infos && $infos->{name}; $snap->{PUBLISHER} = $infos->{publisher}; # Cleanup publisher from 'starred' if verified