(files []ImageFile, reorder bool, resolver protoencoding.Resolver)
| 33 | } |
| 34 | |
| 35 | func newImage(files []ImageFile, reorder bool, resolver protoencoding.Resolver) (*image, error) { |
| 36 | if len(files) == 0 { |
| 37 | return nil, errors.New("image contains no files") |
| 38 | } |
| 39 | pathToImageFile := make(map[string]ImageFile, len(files)) |
| 40 | type commitIDAndFilePath struct { |
| 41 | commitID uuid.UUID |
| 42 | filePath string |
| 43 | } |
| 44 | moduleFullNameStringToCommitIDAndFilePath := make(map[string]commitIDAndFilePath) |
| 45 | for _, file := range files { |
| 46 | path := file.Path() |
| 47 | if _, ok := pathToImageFile[path]; ok { |
| 48 | return nil, fmt.Errorf("duplicate file: %s", path) |
| 49 | } |
| 50 | pathToImageFile[path] = file |
| 51 | if moduleFullName := file.FullName(); moduleFullName != nil { |
| 52 | moduleFullNameString := moduleFullName.String() |
| 53 | existing, ok := moduleFullNameStringToCommitIDAndFilePath[moduleFullNameString] |
| 54 | if ok { |
| 55 | if existing.commitID != file.CommitID() { |
| 56 | return nil, fmt.Errorf( |
| 57 | "files with different commits for the same module %s: %s:%s and %s:%s", |
| 58 | moduleFullNameString, |
| 59 | existing.filePath, |
| 60 | uuidutil.ToDashless(existing.commitID), |
| 61 | path, |
| 62 | uuidutil.ToDashless(file.CommitID()), |
| 63 | ) |
| 64 | } |
| 65 | } else { |
| 66 | moduleFullNameStringToCommitIDAndFilePath[moduleFullNameString] = commitIDAndFilePath{ |
| 67 | commitID: file.CommitID(), |
| 68 | filePath: path, |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | if reorder { |
| 74 | files = orderImageFiles(files, pathToImageFile) |
| 75 | } |
| 76 | if resolver == nil { |
| 77 | fileDescriptorProtos := make([]*descriptorpb.FileDescriptorProto, len(files)) |
| 78 | for i := range files { |
| 79 | fileDescriptorProtos[i] = files[i].FileDescriptorProto() |
| 80 | } |
| 81 | resolver = protoencoding.NewLazyResolver(fileDescriptorProtos...) |
| 82 | } |
| 83 | return &image{ |
| 84 | files: files, |
| 85 | pathToImageFile: pathToImageFile, |
| 86 | resolver: resolver, |
| 87 | }, nil |
| 88 | } |
| 89 | |
| 90 | func newImageNoValidate(files []ImageFile, resolver protoencoding.Resolver) *image { |
| 91 | pathToImageFile := make(map[string]ImageFile, len(files)) |
no test coverage detected
searching dependent graphs…