Blob Blame History Raw
From 118b4127ed490d74429759f4fb8bf5a38b528fba Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Sun, 6 Feb 2022 03:49:16 -0500
Subject: [PATCH 3/7] Suggest optional packages to install if missing

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 builder/jobs.go | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/builder/jobs.go b/builder/jobs.go
index a23d0753..2380f683 100644
--- a/builder/jobs.go
+++ b/builder/jobs.go
@@ -7,6 +7,7 @@ import (
 	"container/heap"
 	"errors"
 	"fmt"
+	"os"
 	"runtime"
 	"sort"
 	"strings"
@@ -37,6 +38,22 @@ type compileJob struct {
 	duration     time.Duration // how long it took to run this job (only set after finishing)
 }
 
+// checkIfPackagedFileExistsJob returns a new *compileJob that checks if a file
+// exists. If the file does not exist, the job will fail with an error
+// suggesting to install the named system packageToInstall.
+func checkIfPackagedFileExistsJob(fileName, packageToInstall string) *compileJob {
+	return &compileJob{
+		description: fmt.Sprintf("check if %v exists", fileName),
+		result:      fileName,
+		run: func(*compileJob) (err error) {
+			if _, err := os.Stat(fileName); errors.Is(err, os.ErrNotExist) {
+				return fmt.Errorf("%v does not exist; please install %v via dnf", fileName, packageToInstall)
+			}
+			return nil
+		},
+	}
+}
+
 // dummyCompileJob returns a new *compileJob that produces an output without
 // doing anything. This can be useful where a *compileJob producing an output is
 // expected but nothing needs to be done, for example for a load from a cache.
-- 
2.41.0