MCPcopy Create free account
hub / github.com/diillson/chatcli / readIgnoreFile

Function readIgnoreFile

utils/file_utils.go:474–502  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
474func 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}

Callers 1

loadIgnorePatternsFunction · 0.85

Calls 5

WarnMethod · 0.80
ScanMethod · 0.80
ErrorMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected