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 chown
import (
"fmt"
"os"
"path"
"strconv"
"github.com/warewulf/warewulf/internal/pkg/overlay"
@@ -13,7 +12,6 @@ import (
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var overlaySourceDir string
var uid int
var gid int
var err error
@@ -34,19 +32,21 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} else {
gid = -1
}
err = overlay.CloneSiteOverlay(overlayName)
if err != nil {
return err
}
overlaySourceDir, _ = overlay.GetOverlay(overlayName)
if !util.IsDir(overlaySourceDir) {
overlay_ := overlay.GetOverlay(overlayName)
if !overlay_.Exists() {
return fmt.Errorf("overlay does not exist: %s", overlayName)
}
overlayFile := path.Join(overlaySourceDir, fileName)
if !overlay_.IsSiteOverlay() {
overlay_, err = overlay_.CloneSiteOverlay()
if err != nil {
return err
}
}
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)
}