66 "fmt"
77 "os"
88 "path/filepath"
9+ "strconv"
910 "sync"
1011
1112 "github.com/docker/buildx/util/confutil"
@@ -14,6 +15,7 @@ import (
1415)
1516
1617const (
18+ version = 2
1719 refsDir = "refs"
1820 groupDir = "__group__"
1921)
@@ -31,12 +33,8 @@ type State struct {
3133}
3234
3335type StateGroup struct {
34- // Definition is the raw representation of the group (bake definition)
35- Definition []byte
3636 // Targets are the targets invoked
3737 Targets []string `json:",omitempty"`
38- // Inputs are the user inputs (bake overrides)
39- Inputs []string `json:",omitempty"`
4038 // Refs are used to track all the refs that belong to the same group
4139 Refs []string
4240}
@@ -52,9 +50,7 @@ func New(cfg *confutil.Config) (*LocalState, error) {
5250 if err := cfg .MkdirAll (refsDir , 0700 ); err != nil {
5351 return nil , err
5452 }
55- return & LocalState {
56- cfg : cfg ,
57- }, nil
53+ return & LocalState {cfg : cfg }, nil
5854}
5955
6056func (ls * LocalState ) ReadRef (builderName , nodeName , id string ) (* State , error ) {
@@ -87,8 +83,12 @@ func (ls *LocalState) SaveRef(builderName, nodeName, id string, st State) error
8783 return ls .cfg .AtomicWriteFile (filepath .Join (refDir , id ), dt , 0644 )
8884}
8985
86+ func (ls * LocalState ) GroupDir () string {
87+ return filepath .Join (ls .cfg .Dir (), refsDir , groupDir )
88+ }
89+
9090func (ls * LocalState ) ReadGroup (id string ) (* StateGroup , error ) {
91- dt , err := os .ReadFile (filepath .Join (ls .cfg . Dir (), refsDir , groupDir , id ))
91+ dt , err := os .ReadFile (filepath .Join (ls .GroupDir () , id ))
9292 if err != nil {
9393 return nil , err
9494 }
@@ -208,7 +208,7 @@ func (ls *LocalState) removeGroup(id string) error {
208208 if id == "" {
209209 return errors .Errorf ("group ref empty" )
210210 }
211- f := filepath .Join (ls .cfg . Dir (), refsDir , groupDir , id )
211+ f := filepath .Join (ls .GroupDir () , id )
212212 if _ , err := os .Lstat (f ); err != nil {
213213 if ! os .IsNotExist (err ) {
214214 return err
@@ -230,3 +230,16 @@ func (ls *LocalState) validate(builderName, nodeName, id string) error {
230230 }
231231 return nil
232232}
233+
234+ func (ls * LocalState ) readVersion () int {
235+ if vdt , err := os .ReadFile (filepath .Join (ls .cfg .Dir (), refsDir , "version" )); err == nil {
236+ if v , err := strconv .Atoi (string (vdt )); err == nil {
237+ return v
238+ }
239+ }
240+ return 1
241+ }
242+
243+ func (ls * LocalState ) writeVersion (version int ) error {
244+ return ls .cfg .AtomicWriteFile (filepath .Join (refsDir , "version" ), []byte (strconv .Itoa (version )), 0600 )
245+ }
0 commit comments