MCPcopy Create free account
hub / github.com/bufbuild/buf / newModuleData

Function newModuleData

private/bufpkg/bufmodule/module_data.go:105–174  ·  view source on GitHub ↗
(
	ctx context.Context,
	moduleKey ModuleKey,
	getBucket func() (storage.ReadBucket, error),
	getDepModuleKeys func() ([]ModuleKey, error),
	getV1BufYAMLObjectData func() (ObjectData, error),
	getV1BufLockObjectData func() (ObjectData, error),
)

Source from the content-addressed store, hash-verified

103}
104
105func newModuleData(
106 ctx context.Context,
107 moduleKey ModuleKey,
108 getBucket func() (storage.ReadBucket, error),
109 getDepModuleKeys func() ([]ModuleKey, error),
110 getV1BufYAMLObjectData func() (ObjectData, error),
111 getV1BufLockObjectData func() (ObjectData, error),
112) *moduleData {
113 moduleData := &moduleData{
114 moduleKey: moduleKey,
115 getBucket: getSyncOnceValuesGetBucketWithStorageMatcherApplied(ctx, getBucket),
116 getDepModuleKeys: sync.OnceValues(getDepModuleKeys),
117 getV1BufYAMLObjectData: sync.OnceValues(getV1BufYAMLObjectData),
118 getV1BufLockObjectData: sync.OnceValues(getV1BufLockObjectData),
119 }
120 moduleData.checkDigest = sync.OnceValue(
121 func() error {
122 // We have to use the get.* functions so that we don't invoke checkDigest.
123 bucket, err := moduleData.getBucket()
124 if err != nil {
125 return err
126 }
127 expectedDigest, err := moduleKey.Digest()
128 if err != nil {
129 return err
130 }
131 var actualDigest Digest
132 switch expectedDigest.Type() {
133 case DigestTypeB4:
134 // Call unexported func instead of exported method to avoid deadlocking on checking the digest again.
135 v1BufYAMLObjectData, err := moduleData.getV1BufYAMLObjectData()
136 if err != nil {
137 return err
138 }
139 // Call unexported func instead of exported method to avoid deadlocking on checking the digest again.
140 v1BufLockObjectData, err := moduleData.getV1BufLockObjectData()
141 if err != nil {
142 return err
143 }
144 actualDigest, err = getB4Digest(ctx, bucket, v1BufYAMLObjectData, v1BufLockObjectData)
145 if err != nil {
146 return err
147 }
148 case DigestTypeB5:
149 // Call unexported func instead of exported method to avoid deadlocking on checking the digest again.
150 depModuleKeys, err := moduleData.getDepModuleKeys()
151 if err != nil {
152 return err
153 }
154 // The B5 digest is calculated based on the dependencies.
155 // The dependencies are not required to be resolved to a Module to calculate this Digest.
156 // Each ModuleKey includes the expected Digest which is validated when loading that dependencies ModuleData, if needed.
157 actualDigest, err = getB5DigestForBucketAndDepModuleKeys(ctx, bucket, depModuleKeys)
158 if err != nil {
159 return err
160 }
161 }
162 if !DigestEqual(expectedDigest, actualDigest) {

Callers 1

NewModuleDataFunction · 0.85

Calls 8

getB4DigestFunction · 0.85
DigestEqualFunction · 0.70
DigestMethod · 0.65
TypeMethod · 0.65
FullNameMethod · 0.65
CommitIDMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…