Browse Source

Don't use fail function in findMarkupFiles()

renovate/configure
Yota Toyama 8 years ago
parent
commit
52ca3d81cd
  1. 23
      main.go
  2. 11
      utils.go

23
main.go

@ -1,6 +1,9 @@
package main package main
import "os" import (
"os"
"sync"
)
const filesCapacity = 1024 const filesCapacity = 1024
@ -8,13 +11,23 @@ func main() {
args, err := getArguments(nil) args, err := getArguments(nil)
if err != nil { if err != nil {
printToStderr(err.Error()) fail(err)
os.Exit(1)
} }
fc := make(chan string, filesCapacity) fc := make(chan string, filesCapacity)
ec := make(chan error, 64)
wg := sync.WaitGroup{}
go findMarkupFiles(args.filenames, args.recursive, fc, ec)
go findMarkupFiles(args.filenames, args.recursive, fc) wg.Add(1)
go func() {
for e := range ec {
fail(e)
}
wg.Done()
}()
rc := make(chan fileResult, filesCapacity) rc := make(chan fileResult, filesCapacity)
s := newSemaphore(args.concurrency) s := newSemaphore(args.concurrency)
@ -33,6 +46,8 @@ func main() {
} }
} }
wg.Wait()
if !ok { if !ok {
os.Exit(1) os.Exit(1)
} }

11
utils.go

@ -55,27 +55,28 @@ func listDirectory(d string, fc chan<- string) error {
}) })
} }
func findMarkupFiles(fs []string, recursive bool, fc chan<- string) { func findMarkupFiles(fs []string, recursive bool, fc chan<- string, ec chan<- error) {
for _, f := range fs { for _, f := range fs {
i, err := os.Stat(f) i, err := os.Stat(f)
if err != nil { if err != nil {
fail(err) ec <- err
continue
} }
if i.IsDir() && recursive { if i.IsDir() && recursive {
err := listDirectory(f, fc) err := listDirectory(f, fc)
if err != nil { if err != nil {
fail(err) ec <- err
} }
} else if i.IsDir() { } else if i.IsDir() {
fail(fmt.Errorf("%v is not a file", f)) ec <- fmt.Errorf("%v is not a file", f)
} else { } else {
fc <- f fc <- f
} }
} }
close(fc) close(fc)
close(ec)
} }

Loading…
Cancel
Save