From b9f0ef1c559df7c6923ddbf0f681b79cca2925e3 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 23 Jan 2021 22:01:29 +0100 Subject: [PATCH] Implement ImageExists in the img backend --- pkg/compiler/backend/simpleimg.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/compiler/backend/simpleimg.go b/pkg/compiler/backend/simpleimg.go index 6ba7da75..caea55bb 100644 --- a/pkg/compiler/backend/simpleimg.go +++ b/pkg/compiler/backend/simpleimg.go @@ -18,6 +18,7 @@ package backend import ( "os" "os/exec" + "strings" "github.com/mudler/luet/pkg/compiler" . "github.com/mudler/luet/pkg/logger" @@ -106,10 +107,16 @@ func (*SimpleImg) ImageAvailable(imagename string) bool { return imageAvailable(imagename) } +// ImageExists check if the given image is available locally func (*SimpleImg) ImageExists(imagename string) bool { - // NOOP: not implemented - // TODO: Since img doesn't have an inspect command, - // we need to parse the ls output manually + cmd := exec.Command("img", "ls") + out, err := cmd.Output() + if err != nil { + return false + } + if strings.Contains(string(out), imagename) { + return true + } return false }