Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
upils committed Oct 4, 2023
1 parent 133efd9 commit bcac752
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/statemachine/classic_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ func (stateMachine *StateMachine) makeQcow2Img() error {
// updateBootloader determines the bootloader for each volume
// and runs the correct helper function to update the bootloader
func (stateMachine *StateMachine) updateBootloader() error {
fmt.Printf("stateMachine.rootfsVolName: %s", stateMachine.rootfsVolName)
if stateMachine.rootfsPartNum == -1 || stateMachine.rootfsVolName == "" {
return fmt.Errorf("Error: could not determine partition number of the root filesystem")
}
Expand Down
5 changes: 4 additions & 1 deletion internal/statemachine/common_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (stateMachine *StateMachine) makeTemporaryDirectories() error {
stateMachine.tempDirs.chroot = filepath.Join(stateMachine.stateMachineFlags.WorkDir, "chroot")
stateMachine.tempDirs.scratch = filepath.Join(stateMachine.stateMachineFlags.WorkDir, "scratch")

tempDirs := []string{stateMachine.tempDirs.scratch, stateMachine.tempDirs.rootfs}
tempDirs := []string{stateMachine.tempDirs.scratch, stateMachine.tempDirs.rootfs, stateMachine.tempDirs.unpack}
for _, tempDir := range tempDirs {
err := osMkdir(tempDir, 0755)
if err != nil && !os.IsExist(err) {
Expand Down Expand Up @@ -117,6 +117,9 @@ func (stateMachine *StateMachine) loadGadgetYaml() error {
// in various places
stateMachine.SectorSize, _ = quantity.ParseSize(stateMachine.commonFlags.SectorSize)

fmt.Printf("statemachine: %+v\n", stateMachine)
fmt.Printf("gadgetInfo.Volumes: %+v\n", stateMachine.GadgetInfo.Volumes)

return nil
}

Expand Down
6 changes: 5 additions & 1 deletion internal/statemachine/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import (

var packStates = []stateFunc{
{"prepare_pack", (*StateMachine).preparePack},
{"make_temporary_directories", (*StateMachine).makeTemporaryDirectories},
{"populate_temporary_directories", (*StateMachine).populateTemporaryDirectories},
{"load_gadget_yaml", (*StateMachine).loadGadgetYaml},
{"set_artifact_names", (*StateMachine).setArtifactNames},
{"calculate_rootfs_size", (*StateMachine).calculateRootfsSize},
{"populate_bootfs_contents", (*StateMachine).populateBootfsContents},
{"populate_prepare_partitions", (*StateMachine).populatePreparePartitions},
{"make_disk", (*StateMachine).makeDisk},
{"update_bootloader", (*StateMachine).updateBootloader},
{"finish", (*StateMachine).finish},
}

// PackStateMachine embeds StateMachine and adds the command line flags specific to pack images
Expand All @@ -24,7 +28,7 @@ type PackStateMachine struct {

// Setup assigns variables and calls other functions that must be executed before Run()
func (packStateMachine *PackStateMachine) Setup() error {
fmt.Printf("WARNING: this is an experimental feature.")
fmt.Print("WARNING: this is an experimental feature.\n")

// set the parent pointer of the embedded struct
packStateMachine.parent = packStateMachine
Expand Down
43 changes: 42 additions & 1 deletion internal/statemachine/pack_states.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
package statemachine

import "path/filepath"
import (
"fmt"
"os"
"path/filepath"
)

func (stateMachine *StateMachine) preparePack() error {
packStateMachine := stateMachine.parent.(*PackStateMachine)

packStateMachine.YamlFilePath = filepath.Join(packStateMachine.Opts.GadgetDir, "meta", "gadget.yaml")

return nil
}

func (stateMachine *StateMachine) populateTemporaryDirectories() error {
packStateMachine := stateMachine.parent.(*PackStateMachine)

files, err := osReadDir(packStateMachine.Opts.RootfsDir)
if err != nil {
return fmt.Errorf("Error reading rootfs dir: %s", err.Error())
}

for _, srcFile := range files {
srcFile := filepath.Join(packStateMachine.Opts.RootfsDir, srcFile.Name())
if err := osutilCopySpecialFile(srcFile, stateMachine.tempDirs.rootfs); err != nil {
return fmt.Errorf("Error copying rootfs: %s", err.Error())
}
}

// make the gadget directory under unpack
gadgetDir := filepath.Join(stateMachine.tempDirs.unpack, "gadget")

err = osMkdir(gadgetDir, 0755)
if err != nil && !os.IsExist(err) {
return fmt.Errorf("Error creating scratch/gadget directory: %s", err.Error())
}

gfiles, err := osReadDir(packStateMachine.Opts.GadgetDir)
if err != nil {
return fmt.Errorf("Error reading gadget dir: %s", err.Error())
}

for _, srcFile := range gfiles {
srcFile := filepath.Join(packStateMachine.Opts.GadgetDir, srcFile.Name())
if err := osutilCopySpecialFile(srcFile, gadgetDir); err != nil {
return fmt.Errorf("Error copying gadget: %s", err.Error())
}
}

return nil
}

0 comments on commit bcac752

Please sign in to comment.