Add an Overlay type with helper methods

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-12-18 11:35:57 -07:00
committed by Christian Goll
parent 7d4b7ab432
commit c03dc9436b
14 changed files with 307 additions and 176 deletions

View File

@@ -3,7 +3,6 @@ package chmod
import (
"fmt"
"os"
"path"
"strconv"
"github.com/spf13/cobra"
@@ -12,8 +11,6 @@ import (
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var overlaySourceDir string
overlayName := args[0]
fileName := args[1]
@@ -21,19 +18,19 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("could not convert requested mode: %s", err)
}
err = overlay.CloneSiteOverlay(overlayName)
if err != nil {
return err
overlay_ := overlay.GetOverlay(overlayName)
if !overlay_.IsSiteOverlay() {
overlay_, err = overlay_.CloneSiteOverlay()
if err != nil {
return err
}
}
overlaySourceDir, _ = overlay.GetOverlay(overlayName)
if !util.IsDir(overlaySourceDir) {
if !overlay_.Exists() {
return fmt.Errorf("overlay does not exist: %s", overlayName)
}
overlayFile := path.Join(overlaySourceDir, fileName)
if !util.IsFile(overlayFile) && !util.IsDir(overlayFile) {
overlayFile := overlay_.File(fileName)
if !(util.IsFile(overlayFile) || util.IsDir(overlayFile)) {
return fmt.Errorf("file does not exist within overlay: %s:%s", overlayName, fileName)
}