MCPcopy Index your code
hub / github.com/coder/coder / Rebuild

Method Rebuild

agent/filefinder/engine.go:236–264  ·  view source on GitHub ↗

Rebuild forces a complete re-walk and re-index of a root.

(ctx context.Context, root string)

Source from the content-addressed store, hash-verified

234
235// Rebuild forces a complete re-walk and re-index of a root.
236func (e *Engine) Rebuild(ctx context.Context, root string) error {
237 absRoot, err := filepath.Abs(root)
238 if err != nil {
239 return xerrors.Errorf("resolve root: %w", err)
240 }
241
242 // Walk outside the lock to avoid blocking the event
243 // pipeline on potentially slow filesystem I/O.
244 idx, walkErr := walkRoot(absRoot)
245 if walkErr != nil {
246 return xerrors.Errorf("rebuild walk: %w", walkErr)
247 }
248
249 e.mu.Lock()
250 rs, exists := e.roots[absRoot]
251 if !exists {
252 e.mu.Unlock()
253 return xerrors.Errorf("root %q not found", absRoot)
254 }
255 rs.index = idx
256 e.publishSnapshot()
257 fileCount := idx.Len()
258 e.mu.Unlock()
259 e.logger.Info(ctx, "rebuilt root in engine",
260 slog.F("root", absRoot),
261 slog.F("files", fileCount),
262 )
263 return nil
264}
265
266func (e *Engine) start() {
267 defer e.wg.Done()

Callers 1

TestEngine_RebuildFunction · 0.80

Calls 7

publishSnapshotMethod · 0.95
walkRootFunction · 0.85
ErrorfMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45
LenMethod · 0.45
InfoMethod · 0.45

Tested by 1

TestEngine_RebuildFunction · 0.64