(root string, allowFallback bool)
| 108 | } |
| 109 | |
| 110 | func getHubInfoWithFallback(root string, allowFallback bool) *hubInfo { |
| 111 | if state := watch.ReadState(root); state != nil { |
| 112 | // State may contain file/event info only (no dependency graph) on very |
| 113 | // large repos. Avoid expensive fallback scans in that case. |
| 114 | if len(state.Importers) == 0 && len(state.Imports) == 0 && len(state.Hubs) == 0 { |
| 115 | return nil |
| 116 | } |
| 117 | return &hubInfo{ |
| 118 | Hubs: state.Hubs, |
| 119 | Importers: state.Importers, |
| 120 | Imports: state.Imports, |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if !allowFallback { |
| 125 | return nil |
| 126 | } |
| 127 | |
| 128 | // If daemon is running but state is unavailable, skip expensive fallback. |
| 129 | if watch.IsRunning(root) { |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | // Fall back to fresh scan only when daemon is not running. |
| 134 | fg, err := scanner.BuildFileGraph(root) |
| 135 | if err != nil { |
| 136 | return nil |
| 137 | } |
| 138 | |
| 139 | return &hubInfo{ |
| 140 | Hubs: fg.HubFiles(), |
| 141 | Importers: fg.Importers, |
| 142 | Imports: fg.Imports, |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // RunHookWithTimeout executes a hook with a hard timeout. |
| 147 | // On timeout, returns HookTimeoutError and callers should fail open. |
no test coverage detected