github.com/canonical/ubuntu-image@v0.0.0-20240430122802-2202fe98b290/internal/statemachine/snap.go (about) 1 package statemachine 2 3 import ( 4 "github.com/canonical/ubuntu-image/internal/commands" 5 ) 6 7 // snapStates are the names and function variables to be executed by the state machine for snap images 8 var snapStates = []stateFunc{ 9 prepareImageState, 10 loadGadgetYamlState, 11 setArtifactNamesState, 12 populateSnapRootfsContentsState, 13 generateDiskInfoState, 14 calculateRootfsSizeState, 15 populateBootfsContentsState, 16 populatePreparePartitionsState, 17 makeDiskState, 18 generateSnapManifestState, 19 } 20 21 // SnapStateMachine embeds StateMachine and adds the command line flags specific to snap images 22 type SnapStateMachine struct { 23 StateMachine 24 Opts commands.SnapOpts 25 Args commands.SnapArgs 26 } 27 28 // Setup assigns variables and calls other functions that must be executed before Run(). 29 func (snapStateMachine *SnapStateMachine) Setup() error { 30 // set the parent pointer of the embedded struct 31 snapStateMachine.parent = snapStateMachine 32 33 // set the states that will be used for this image type 34 snapStateMachine.states = snapStates 35 36 if err := snapStateMachine.setConfDefDir(snapStateMachine.parent.(*SnapStateMachine).Args.ModelAssertion); err != nil { 37 return err 38 } 39 40 // do the validation common to all image types 41 if err := snapStateMachine.validateInput(); err != nil { 42 return err 43 } 44 45 // validate values of until and thru 46 if err := snapStateMachine.validateUntilThru(); err != nil { 47 return err 48 } 49 50 // if --resume was passed, figure out where to start 51 if err := snapStateMachine.readMetadata(metadataStateFile); err != nil { 52 return err 53 } 54 55 snapStateMachine.displayStates() 56 57 if snapStateMachine.commonFlags.DryRun { 58 return nil 59 } 60 61 if err := snapStateMachine.makeTemporaryDirectories(); err != nil { 62 return err 63 } 64 65 return snapStateMachine.determineOutputDirectory() 66 }