Simplification
This commit is contained in:
parent
570c65db08
commit
12e62912c8
35
goldsmith.go
35
goldsmith.go
@ -23,22 +23,27 @@
|
||||
package goldsmith
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
type goldsmith struct {
|
||||
srcDir, dstDir string
|
||||
refs map[string]bool
|
||||
mtx sync.Mutex
|
||||
stages []*stage
|
||||
active int64
|
||||
stalled int64
|
||||
tainted bool
|
||||
|
||||
stages []*stage
|
||||
active int64
|
||||
stalled int64
|
||||
|
||||
refs map[string]bool
|
||||
refMtx sync.Mutex
|
||||
|
||||
tainted bool
|
||||
faultMtx sync.Mutex
|
||||
}
|
||||
|
||||
func (gs *goldsmith) queueFiles(target uint) {
|
||||
@ -125,8 +130,8 @@ func (gs *goldsmith) exportFile(f *file) error {
|
||||
}
|
||||
|
||||
func (gs *goldsmith) referenceFile(path string) {
|
||||
gs.mtx.Lock()
|
||||
defer gs.mtx.Unlock()
|
||||
gs.refMtx.Lock()
|
||||
defer gs.refMtx.Unlock()
|
||||
|
||||
if gs.refs == nil {
|
||||
gs.refs = make(map[string]bool)
|
||||
@ -144,8 +149,16 @@ func (gs *goldsmith) referenceFile(path string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (gs *goldsmith) fault(s *stage, f *file, err error) {
|
||||
log.Printf("%s\t%s\t%s", s.name, f.path, err)
|
||||
func (gs *goldsmith) fault(s *stage, step string, f *file, err error) {
|
||||
gs.faultMtx.Lock()
|
||||
defer gs.faultMtx.Unlock()
|
||||
|
||||
color.Red("Fault Detected\n")
|
||||
color.Yellow("\tPlugin:\t%s\n", color.WhiteString(s.name))
|
||||
color.Yellow("\tStep:\t%s\n", color.WhiteString(step))
|
||||
color.Yellow("\tFile:\t%s\n", color.WhiteString(f.path))
|
||||
color.Yellow("\tError:\t%s\n\n", color.WhiteString(err.Error()))
|
||||
|
||||
gs.tainted = true
|
||||
}
|
||||
|
||||
|
7
stage.go
7
stage.go
@ -45,6 +45,7 @@ func newStage(gs *goldsmith) *stage {
|
||||
|
||||
func (s *stage) chain(p Plugin) {
|
||||
defer close(s.output)
|
||||
s.name = p.Name()
|
||||
|
||||
init, _ := p.(Initializer)
|
||||
accept, _ := p.(Accepter)
|
||||
@ -71,7 +72,7 @@ func (s *stage) chain(p Plugin) {
|
||||
|
||||
if init != nil {
|
||||
if err := init.Initialize(s); err != nil {
|
||||
s.gs.fault(s, nil, err)
|
||||
s.gs.fault(s, "Initialization", nil, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -88,7 +89,7 @@ func (s *stage) chain(p Plugin) {
|
||||
|
||||
f.rewind()
|
||||
if err := proc.Process(s, f); err != nil {
|
||||
s.gs.fault(s, f, err)
|
||||
s.gs.fault(s, "Processing", f, err)
|
||||
}
|
||||
|
||||
dispatch(f)
|
||||
@ -100,7 +101,7 @@ func (s *stage) chain(p Plugin) {
|
||||
|
||||
if fin != nil {
|
||||
if err := fin.Finalize(s, batch); err != nil {
|
||||
s.gs.fault(s, nil, err)
|
||||
s.gs.fault(s, "Finalization", nil, err)
|
||||
}
|
||||
|
||||
for _, f := range batch {
|
||||
|
6
types.go
6
types.go
@ -34,17 +34,13 @@ type Goldsmith interface {
|
||||
}
|
||||
|
||||
func New(srcDir, dstDir string) Goldsmith {
|
||||
return NewThrottled(srcDir, dstDir, uint(runtime.NumCPU()))
|
||||
}
|
||||
|
||||
func NewThrottled(srcDir, dstDir string, targetFileCount uint) Goldsmith {
|
||||
gs := &goldsmith{
|
||||
srcDir: srcDir,
|
||||
dstDir: dstDir,
|
||||
refs: make(map[string]bool),
|
||||
}
|
||||
|
||||
gs.queueFiles(targetFileCount)
|
||||
gs.queueFiles(uint(runtime.NumCPU()))
|
||||
return gs
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user