| 122 | } |
| 123 | |
| 124 | func (bl *BootstrapLoader) loadWithCache(path string) (string, bool) { |
| 125 | info, err := os.Stat(path) |
| 126 | if err != nil { |
| 127 | return "", false |
| 128 | } |
| 129 | |
| 130 | bl.mu.RLock() |
| 131 | cached, found := bl.cache[path] |
| 132 | bl.mu.RUnlock() |
| 133 | |
| 134 | if found && !info.ModTime().After(cached.modTime) { |
| 135 | return cached.content, true |
| 136 | } |
| 137 | |
| 138 | data, err := os.ReadFile(path) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream) |
| 139 | if err != nil { |
| 140 | bl.logger.Debug("failed to read bootstrap file", zap.String("path", path), zap.Error(err)) |
| 141 | return "", false |
| 142 | } |
| 143 | |
| 144 | content := string(data) |
| 145 | bl.mu.Lock() |
| 146 | bl.cache[path] = cachedFile{ |
| 147 | content: content, |
| 148 | modTime: info.ModTime(), |
| 149 | } |
| 150 | bl.mu.Unlock() |
| 151 | |
| 152 | return content, true |
| 153 | } |