readIgnoreFile lê um único arquivo de ignore e retorna os padrões de exclusão. Retorna slices nulos se o arquivo não existir ou não puder ser lido.
(filePath string, logger *zap.Logger)
| 472 | // readIgnoreFile lê um único arquivo de ignore e retorna os padrões de exclusão. |
| 473 | // Retorna slices nulos se o arquivo não existir ou não puder ser lido. |
| 474 | func readIgnoreFile(filePath string, logger *zap.Logger) (excludeDirs []string, excludePatterns []string) { |
| 475 | file, err := os.Open(filePath) //#nosec G304 G703 -- path validated by engine.validatePath / SensitiveReadPaths.IsReadAllowed |
| 476 | if err != nil { |
| 477 | if !os.IsNotExist(err) { |
| 478 | logger.Warn("Não foi possível abrir o arquivo de ignore, pulando.", zap.String("path", filePath), zap.Error(err)) |
| 479 | } |
| 480 | return nil, nil |
| 481 | } |
| 482 | defer file.Close() |
| 483 | |
| 484 | var dirs, patterns []string |
| 485 | scanner := bufio.NewScanner(file) |
| 486 | for scanner.Scan() { |
| 487 | line := strings.TrimSpace(scanner.Text()) |
| 488 | if line == "" || strings.HasPrefix(line, "#") { |
| 489 | continue |
| 490 | } |
| 491 | if strings.HasSuffix(line, "/") { |
| 492 | dirs = append(dirs, strings.TrimSuffix(line, "/")) |
| 493 | } else { |
| 494 | patterns = append(patterns, line) |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if err := scanner.Err(); err != nil { |
| 499 | logger.Warn("Erro ao escanear o arquivo de ignore.", zap.String("path", filePath), zap.Error(err)) |
| 500 | } |
| 501 | return dirs, patterns |
| 502 | } |