6
6
"fmt"
7
7
"os"
8
8
"path/filepath"
9
+ "strconv"
9
10
"sync"
10
11
11
12
"github.com/docker/buildx/util/confutil"
@@ -14,6 +15,7 @@ import (
14
15
)
15
16
16
17
const (
18
+ version = 2
17
19
refsDir = "refs"
18
20
groupDir = "__group__"
19
21
)
@@ -31,12 +33,8 @@ type State struct {
31
33
}
32
34
33
35
type StateGroup struct {
34
- // Definition is the raw representation of the group (bake definition)
35
- Definition []byte
36
36
// Targets are the targets invoked
37
37
Targets []string `json:",omitempty"`
38
- // Inputs are the user inputs (bake overrides)
39
- Inputs []string `json:",omitempty"`
40
38
// Refs are used to track all the refs that belong to the same group
41
39
Refs []string
42
40
}
@@ -52,9 +50,7 @@ func New(cfg *confutil.Config) (*LocalState, error) {
52
50
if err := cfg .MkdirAll (refsDir , 0700 ); err != nil {
53
51
return nil , err
54
52
}
55
- return & LocalState {
56
- cfg : cfg ,
57
- }, nil
53
+ return & LocalState {cfg : cfg }, nil
58
54
}
59
55
60
56
func (ls * LocalState ) ReadRef (builderName , nodeName , id string ) (* State , error ) {
@@ -87,8 +83,12 @@ func (ls *LocalState) SaveRef(builderName, nodeName, id string, st State) error
87
83
return ls .cfg .AtomicWriteFile (filepath .Join (refDir , id ), dt , 0644 )
88
84
}
89
85
86
+ func (ls * LocalState ) GroupDir () string {
87
+ return filepath .Join (ls .cfg .Dir (), refsDir , groupDir )
88
+ }
89
+
90
90
func (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 ))
92
92
if err != nil {
93
93
return nil , err
94
94
}
@@ -208,7 +208,7 @@ func (ls *LocalState) removeGroup(id string) error {
208
208
if id == "" {
209
209
return errors .Errorf ("group ref empty" )
210
210
}
211
- f := filepath .Join (ls .cfg . Dir (), refsDir , groupDir , id )
211
+ f := filepath .Join (ls .GroupDir () , id )
212
212
if _ , err := os .Lstat (f ); err != nil {
213
213
if ! os .IsNotExist (err ) {
214
214
return err
@@ -230,3 +230,16 @@ func (ls *LocalState) validate(builderName, nodeName, id string) error {
230
230
}
231
231
return nil
232
232
}
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