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

Method Open

private/bufpkg/bufimage/module_file_resolver.go:68–103  ·  view source on GitHub ↗

Open opens the given path, and tracks the external path and import status. This implements [source.Opener].

(path string)

Source from the content-addressed store, hash-verified

66//
67// This implements [source.Opener].
68func (m *moduleFileResolver) Open(path string) (_ *source.File, retErr error) {
69 moduleFile, moduleErr := m.moduleReadBucket.GetFile(m.ctx, path)
70 if moduleErr != nil {
71 if !errors.Is(moduleErr, fs.ErrNotExist) {
72 return nil, moduleErr
73 }
74 if wktModuleFile, wktErr := datawkt.ReadBucket.Get(m.ctx, path); wktErr == nil {
75 if wktModuleFile.Path() != path {
76 // This should never happen, but just in case
77 return nil, fmt.Errorf("requested path %q but got %q", path, wktModuleFile.Path())
78 }
79 if err := m.addPath(path, path, "", nil, uuid.Nil); err != nil {
80 return nil, err
81 }
82 return readObjectCloserToSourceFile(wktModuleFile)
83 }
84 return nil, moduleErr
85 }
86 defer func() {
87 retErr = errors.Join(retErr, moduleFile.Close())
88 }()
89 if moduleFile.Path() != path {
90 // this should never happen, but just in case
91 return nil, fmt.Errorf("requested path %q but got %q", path, moduleFile.Path())
92 }
93 if err := m.addPath(
94 path,
95 moduleFile.ExternalPath(),
96 moduleFile.LocalPath(),
97 moduleFile.Module().FullName(),
98 moduleFile.Module().CommitID(),
99 ); err != nil {
100 return nil, err
101 }
102 return readObjectCloserToSourceFile(moduleFile)
103}
104
105// ExternalPath returns the external path for the input path.
106//

Callers 1

readConfigFromFileFunction · 0.45

Calls 11

addPathMethod · 0.95
GetFileMethod · 0.65
GetMethod · 0.65
PathMethod · 0.65
CloseMethod · 0.65
ExternalPathMethod · 0.65
LocalPathMethod · 0.65
FullNameMethod · 0.65
ModuleMethod · 0.65
CommitIDMethod · 0.65

Tested by

no test coverage detected