MCPcopy Create free account
hub / github.com/Debian/dcs / ReplaceIndex

Method ReplaceIndex

internal/sourcebackend/sourcebackend.go:198–251  ·  view source on GitHub ↗
(ctx context.Context, in *sourcebackendpb.ReplaceIndexRequest)

Source from the content-addressed store, hash-verified

196
197 for _, name := range names {
198 if name == newShard {
199 newShard = filepath.Join(filepath.Dir(s.IndexPath), name)
200 // We verified the given argument refers to an index shard within
201 // this directory, so let’s load this shard.
202 log.Printf("Trying to load %q\n", newShard)
203 if err := s.LoadIndex(newShard); err != nil {
204 return err
205 }
206
207 if err := renameio.Symlink(newShard, s.IndexPath); err != nil {
208 return err
209 }
210 return nil
211 }
212 }
213
214 return fmt.Errorf("No such shard.")
215}
216
217// TODO: fix the indexing code path to ensure valid UTF8
218// (currently it seems to only reject *some* invalid UTF8)
219func ensureValidUTF8(s string) string {
220 if utf8.ValidString(s) {
221 return s
222 }
223 return strings.ToValidUTF8(s, "\uFFFD")
224}
225
226type fileMatches struct {
227 fn string
228 matches []index.Match
229}
230
231func (s *Server) queryPositional(ix *index.Index, hidden map[string]bool, literal string) ([]fileMatches, error) {
232 matches, err := ix.QueryPositional(literal)
233 if err != nil {
234 return nil, fmt.Errorf("ix.QueryPositional(%q): %v", literal, err)
235 }
236
237 // Split matches into smaller slices (= create new slice headers),
238 // which are kept in memory alongside the file name (fileMatches).
239 var possible []fileMatches
240 for len(matches) > 0 {
241 docid := matches[0].Docid
242 n := 1
243 // Find all matches within this document (source file).
244 for n < len(matches) && matches[n].Docid == docid {
245 n++
246 }
247 fn, err := ix.DocidMap.Lookup(docid)
248 if err != nil {
249 return nil, fmt.Errorf("DocidMap.Lookup(%v): %v", docid, err)
250 }
251 if pkg, _, _ := strings.Cut(fn, "/"); !hidden[pkg] {
252 possible = append(possible, fileMatches{
253 fn: fn,
254 matches: matches[:n],

Callers

nothing calls this directly

Calls 3

OpenFunction · 0.92
NameMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected