Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364package executor
import ( "fmt"
millv1 "tangled.org/core/spindle/mill/proto/gen" "tangled.org/core/spindle/models")
func cacheBindingsFromProto(repoDid string, entries []models.CacheEntry, bindings []*millv1.CacheBinding) ([]models.CacheBinding, error) { result := make([]models.CacheBinding, 0, len(bindings)) seen := make(map[int]struct{}, len(bindings)) for _, binding := range bindings { entryIndex := int(binding.GetEntryIndex()) if entryIndex < 0 || entryIndex >= len(entries) { return nil, fmt.Errorf("cache binding index %d is out of range", entryIndex) } if _, ok := seen[entryIndex]; ok { return nil, fmt.Errorf("duplicate cache binding index %d", entryIndex) } seen[entryIndex] = struct{}{}
for _, object := range []struct { name string id string key string }{ {name: "restore", id: binding.GetRestoreId(), key: binding.GetRestoreKey()}, {name: "save", id: binding.GetSaveId(), key: binding.GetSaveKey()}, } { if (object.id == "") != (object.key == "") { return nil, fmt.Errorf("%s cache id and key must both be set", object.name) } if object.id == "" { continue } want, err := models.CacheObjectKey(repoDid, object.id) if err != nil { return nil, err } if object.key != want { return nil, fmt.Errorf("%s cache key %q does not match object id", object.name, object.key) } }
entry := entries[entryIndex] result = append(result, models.CacheBinding{ EntryIndex: entryIndex, Paths: entry.Paths, Key: entry.Key, SaveID: binding.GetSaveId(), SaveKey: binding.GetSaveKey(), RestoreID: binding.GetRestoreId(), RestoreKey: binding.GetRestoreKey(), RestoreName: binding.GetRestoreName(), Checksum: binding.GetRestoreChecksum(), SizeBytes: binding.GetRestoreSizeBytes(), CompressionLevel: entry.CompressionLevel, When: entry.When, }) } return result, nil}