Rebuild forces a complete re-walk and re-index of a root.
(ctx context.Context, root string)
| 234 | |
| 235 | // Rebuild forces a complete re-walk and re-index of a root. |
| 236 | func (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 | |
| 266 | func (e *Engine) start() { |
| 267 | defer e.wg.Done() |