From 16fd703bc54f3455e8fffc3ff3ebcdb09d83ffd4 Mon Sep 17 00:00:00 2001 From: Christian Zunker Date: Wed, 27 Sep 2023 06:50:18 +0200 Subject: [PATCH] Fix tests Signed-off-by: Christian Zunker --- providers/os/connection/tar.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/providers/os/connection/tar.go b/providers/os/connection/tar.go index 1ac1aefdf8..0f10608b30 100644 --- a/providers/os/connection/tar.go +++ b/providers/os/connection/tar.go @@ -246,10 +246,15 @@ func NewWithClose(id uint32, conf *inventory.Config, asset *inventory.Asset, clo func newWithFlattenedImage(id uint32, conf *inventory.Config, asset *inventory.Asset, img *v1.Image, closeFn func()) (*TarConnection, error) { imageFilename := "" - if asset.Connections[0].Options[FLATTENED_IMAGE] != "" { - log.Debug().Str("tar", asset.Connections[0].Options[FLATTENED_IMAGE]).Msg("tar> use cached tar file") - imageFilename = asset.Connections[0].Options[FLATTENED_IMAGE] - } else { + useCached := false + if asset != nil && len(asset.Connections) > 0 { + if x, ok := asset.Connections[0].Options[FLATTENED_IMAGE]; ok && x != "" { + log.Debug().Str("tar", asset.Connections[0].Options[FLATTENED_IMAGE]).Msg("tar> use cached tar file") + imageFilename = asset.Connections[0].Options[FLATTENED_IMAGE] + useCached = true + } + } + if !useCached { f, err := cache.RandomFile() if err != nil { return nil, err @@ -282,10 +287,12 @@ func newWithFlattenedImage(id uint32, conf *inventory.Config, asset *inventory.A }, }, } - if asset.Connections[0].Options == nil { - asset.Connections[0].Options = map[string]string{} + if asset != nil && len(asset.Connections) > 0 { + if asset.Connections[0].Options == nil { + asset.Connections[0].Options = map[string]string{} + } + asset.Connections[0].Options[FLATTENED_IMAGE] = imageFilename } - asset.Connections[0].Options[FLATTENED_IMAGE] = imageFilename err := c.LoadFile(imageFilename) if err != nil {