Open opens the given path, and tracks the external path and import status. This implements [source.Opener].
(path string)
| 66 | // |
| 67 | // This implements [source.Opener]. |
| 68 | func (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 | // |
no test coverage detected