must set ModuleReadBucket after constructor via setModuleReadBucket
( ctx context.Context, // This function must already be filtered to include only module files and must be sync.OnceValues wrapped! syncOnceValuesGetBucketWithStorageMatcherApplied func() (storage.ReadBucket, error), bucketID string, description string, moduleFullName bufparse.FullName, commitID uuid.UUID, isTarget bool, isLocal bool, getV1BufYAMLObjectData func() (ObjectData, error), getV1BufLockObjectData func() (ObjectData, error), getDepModuleKeysB5 func() ([]ModuleKey, error), targetPaths []string, targetExcludePaths []string, protoFileTargetPath string, includePackageFiles bool, )
| 250 | |
| 251 | // must set ModuleReadBucket after constructor via setModuleReadBucket |
| 252 | func newModule( |
| 253 | ctx context.Context, |
| 254 | // This function must already be filtered to include only module files and must be sync.OnceValues wrapped! |
| 255 | syncOnceValuesGetBucketWithStorageMatcherApplied func() (storage.ReadBucket, error), |
| 256 | bucketID string, |
| 257 | description string, |
| 258 | moduleFullName bufparse.FullName, |
| 259 | commitID uuid.UUID, |
| 260 | isTarget bool, |
| 261 | isLocal bool, |
| 262 | getV1BufYAMLObjectData func() (ObjectData, error), |
| 263 | getV1BufLockObjectData func() (ObjectData, error), |
| 264 | getDepModuleKeysB5 func() ([]ModuleKey, error), |
| 265 | targetPaths []string, |
| 266 | targetExcludePaths []string, |
| 267 | protoFileTargetPath string, |
| 268 | includePackageFiles bool, |
| 269 | ) (*module, error) { |
| 270 | // TODO FUTURE: get these validations into a common place |
| 271 | if protoFileTargetPath != "" && (len(targetPaths) > 0 || len(targetExcludePaths) > 0) { |
| 272 | return nil, syserror.Newf("cannot set both protoFileTargetPath %q and either targetPaths %v or targetExcludePaths %v", protoFileTargetPath, targetPaths, targetExcludePaths) |
| 273 | } |
| 274 | if protoFileTargetPath != "" && normalpath.Ext(protoFileTargetPath) != ".proto" { |
| 275 | return nil, syserror.Newf("protoFileTargetPath %q is not a .proto file", protoFileTargetPath) |
| 276 | } |
| 277 | if bucketID == "" && moduleFullName == nil { |
| 278 | return nil, syserror.New("bucketID was empty and moduleFullName was nil when constructing a Module, one of these must be set") |
| 279 | } |
| 280 | if !isLocal && moduleFullName == nil { |
| 281 | return nil, syserror.New("moduleFullName not present when constructing a remote Module") |
| 282 | } |
| 283 | if moduleFullName == nil && commitID != uuid.Nil { |
| 284 | return nil, syserror.New("moduleFullName not present and commitID present when constructing a remote Module") |
| 285 | } |
| 286 | |
| 287 | normalizeAndValidateIfNotEmpty := func(path string) (string, error) { |
| 288 | if path == "" { |
| 289 | return path, nil |
| 290 | } |
| 291 | return normalpath.NormalizeAndValidate(path) |
| 292 | } |
| 293 | targetPaths, err := xslices.MapError(targetPaths, normalizeAndValidateIfNotEmpty) |
| 294 | if err != nil { |
| 295 | return nil, syserror.Wrap(err) |
| 296 | } |
| 297 | targetExcludePaths, err = xslices.MapError(targetExcludePaths, normalizeAndValidateIfNotEmpty) |
| 298 | if err != nil { |
| 299 | return nil, syserror.Wrap(err) |
| 300 | } |
| 301 | protoFileTargetPath, err = normalizeAndValidateIfNotEmpty(protoFileTargetPath) |
| 302 | if err != nil { |
| 303 | return nil, syserror.Wrap(err) |
| 304 | } |
| 305 | |
| 306 | module := &module{ |
| 307 | ctx: ctx, |
| 308 | getBucket: syncOnceValuesGetBucketWithStorageMatcherApplied, |
| 309 | bucketID: bucketID, |
no test coverage detected
searching dependent graphs…