Skip to content

Commit

Permalink
Skip walking ignored directories
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Jul 1, 2024
1 parent a09d0e5 commit b606548
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cli/cmd/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package start

import (
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -211,16 +212,16 @@ type rillYAML struct {
IgnorePaths []string `yaml:"ignore_paths"`
}

func countFilesInDirectory(path string) (int, error) {
func countFilesInDirectory(projectPath string) (int, error) {
var fileCount int

if path == "" {
path = "."
if projectPath == "" {
projectPath = "."
}

var ignorePaths []string
// Read rill.yaml and get `ignore_paths`
rawYaml, err := os.ReadFile(filepath.Join(path, "/rill.yaml"))
rawYaml, err := os.ReadFile(filepath.Join(projectPath, "/rill.yaml"))
if err == nil {
yml := &rillYAML{}
err = yaml.Unmarshal(rawYaml, yml)
Expand All @@ -229,11 +230,19 @@ func countFilesInDirectory(path string) (int, error) {
}
}

err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
err = filepath.WalkDir(projectPath, func(path string, info fs.DirEntry, err error) error {
if err != nil {
return err
}
if !info.IsDir() && drivers.IsIgnored(path, ignorePaths) {
path = strings.TrimPrefix(path, projectPath)

if drivers.IsIgnored(path, ignorePaths) {
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
if !info.IsDir() {
fileCount++
}
return nil
Expand Down

0 comments on commit b606548

Please sign in to comment.