vendor: update buildkit to master@8b7bcb900d3c

Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
Justin Chadwell
2023-03-29 12:38:36 +01:00
parent c6cdcb02cf
commit 9541457c54
416 changed files with 24398 additions and 16253 deletions

View File

@ -20,15 +20,18 @@ const (
)
type StoreIndex struct {
indexPath string
lockPath string
indexPath string
lockPath string
layoutPath string
}
func NewStoreIndex(storePath string) StoreIndex {
indexPath := path.Join(storePath, indexFile)
layoutPath := path.Join(storePath, ocispecs.ImageLayoutFile)
return StoreIndex{
indexPath: indexPath,
lockPath: indexPath + lockFileSuffix,
indexPath: indexPath,
lockPath: indexPath + lockFileSuffix,
layoutPath: layoutPath,
}
}
@ -58,6 +61,7 @@ func (s StoreIndex) Read() (*ocispecs.Index, error) {
}
func (s StoreIndex) Put(tag string, desc ocispecs.Descriptor) error {
// lock the store to prevent concurrent access
lock := flock.New(s.lockPath)
locked, err := lock.TryLock()
if err != nil {
@ -71,20 +75,33 @@ func (s StoreIndex) Put(tag string, desc ocispecs.Descriptor) error {
os.RemoveAll(s.lockPath)
}()
f, err := os.OpenFile(s.indexPath, os.O_RDWR|os.O_CREATE, 0644)
// create the oci-layout file
layout := ocispecs.ImageLayout{
Version: ocispecs.ImageLayoutVersion,
}
layoutData, err := json.Marshal(layout)
if err != nil {
return err
}
if err := os.WriteFile(s.layoutPath, layoutData, 0644); err != nil {
return err
}
// modify the index file
idxFile, err := os.OpenFile(s.indexPath, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return errors.Wrapf(err, "could not open %s", s.indexPath)
}
defer f.Close()
defer idxFile.Close()
var idx ocispecs.Index
b, err := io.ReadAll(f)
idxData, err := io.ReadAll(idxFile)
if err != nil {
return errors.Wrapf(err, "could not read %s", s.indexPath)
}
if len(b) > 0 {
if err := json.Unmarshal(b, &idx); err != nil {
return errors.Wrapf(err, "could not unmarshal %s (%q)", s.indexPath, string(b))
if len(idxData) > 0 {
if err := json.Unmarshal(idxData, &idx); err != nil {
return errors.Wrapf(err, "could not unmarshal %s (%q)", s.indexPath, string(idxData))
}
}
@ -92,15 +109,15 @@ func (s StoreIndex) Put(tag string, desc ocispecs.Descriptor) error {
return err
}
b, err = json.Marshal(idx)
idxData, err = json.Marshal(idx)
if err != nil {
return err
}
if _, err = f.WriteAt(b, 0); err != nil {
return err
if _, err = idxFile.WriteAt(idxData, 0); err != nil {
return errors.Wrapf(err, "could not write %s", s.indexPath)
}
if err = f.Truncate(int64(len(b))); err != nil {
return err
if err = idxFile.Truncate(int64(len(idxData))); err != nil {
return errors.Wrapf(err, "could not truncate %s", s.indexPath)
}
return nil
}