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
import "os"
import (
"os"
"sync"
)
const filesCapacity = 1024
@ -8,13 +11,23 @@ func main() {
args, err := getArguments(nil)
if err != nil {
printToStderr(err.Error())
os.Exit(1)
fail(err)
}
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)
s := newSemaphore(args.concurrency)
@ -33,6 +46,8 @@ func main() {
}
}
wg.Wait()
if !ok {
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 {
i, err := os.Stat(f)
if err != nil {
fail(err)
ec <- err
continue
}
if i.IsDir() && recursive {
err := listDirectory(f, fc)
if err != nil {
fail(err)
ec <- err
}
} else if i.IsDir() {
fail(fmt.Errorf("%v is not a file", f))
ec <- fmt.Errorf("%v is not a file", f)
} else {
fc <- f
}
}
close(fc)
close(ec)
}

Loading…
Cancel
Save