返回 DeepSeek-Reasonix
shared_rebuild.go
根目录 / internal / taskcatalog / shared_rebuild.go
1 package taskcatalog
2
3 import "context"
4
5 // RebuildSharedCatalog fences the process-local reader, atomically replaces
6 // the disposable database, and reopens it with every project registered during
7 // or before the rebuild.
8 func RebuildSharedCatalog(ctx context.Context, projects []Project) error {
9 return shared.rebuildShared(ctx, projects)
10 }
11
12 func (m *sharedManager) rebuildShared(ctx context.Context, projects []Project) error {
13 m.lifecycleMu.Lock()
14 defer m.lifecycleMu.Unlock()
15 if err := m.closeLocked(ctx, true); err != nil {
16 m.mu.Lock()
17 m.rebuilding = false
18 if m.pending == nil {
19 m.pending = map[string]string{}
20 }
21 for _, project := range projects {
22 project = normalizeProject(project)
23 m.pending[project.Root] = project.Label
24 }
25 m.mu.Unlock()
26 if ctx.Err() == nil {
27 m.start()
28 }
29 return err
30 }
31 m.mu.Lock()
32 if m.pending == nil {
33 m.pending = map[string]string{}
34 }
35 for _, project := range projects {
36 project = normalizeProject(project)
37 m.pending[project.Root] = project.Label
38 }
39 rebuild := m.rebuild
40 if rebuild == nil {
41 rebuild = Rebuild
42 }
43 m.mu.Unlock()
44 _, rebuildErr := rebuild(ctx, "", projects)
45 m.mu.Lock()
46 m.rebuilding = false
47 m.mu.Unlock()
48 if ctx.Err() == nil {
49 m.start()
50 }
51 return rebuildErr
52 }
53
53 lines GO