This commit is contained in:
Alex Yatskov 2015-12-18 13:37:32 +09:00
parent 72347cf724
commit b33e6b7230
3 changed files with 36 additions and 23 deletions

View File

@ -33,7 +33,6 @@ import (
type file struct {
path string
meta map[string]interface{}
srcData *bytes.Reader
srcPath string
}
@ -108,6 +107,10 @@ func (f *file) cache() error {
return nil
}
//
// File Implementation
//
func (f *file) Path() string {
return f.path
}

View File

@ -32,29 +32,25 @@ import (
)
type stage struct {
name string
input, output chan *file
}
type goldsmith struct {
srcDir, dstDir string
stages []*stage
refs map[string]bool
mtx sync.Mutex
stages []*stage
active int64
stalled int64
tainted bool
}
func (gs *goldsmith) fault(s *stage, f *file, err error) {
log.Print("%s\t%s\t%s", s, f, err)
gs.tainted = true
}
func (gs *goldsmith) queueFiles(target uint) {
files := make(chan string)
go scanDir(gs.srcDir, files, nil)
s := gs.newStage()
s := gs.newStage("Goldsmith")
go func() {
defer close(s.output)
@ -132,8 +128,12 @@ func (gs *goldsmith) exportFile(f *file) error {
return nil
}
func (gs *goldsmith) newStage() *stage {
s := &stage{output: make(chan *file)}
func (gs *goldsmith) newStage(name string) *stage {
s := &stage{
name: name,
output: make(chan *file),
}
if len(gs.stages) > 0 {
s.input = gs.stages[len(gs.stages)-1].output
}
@ -206,29 +206,34 @@ func (gs *goldsmith) chain(s *stage, p Plugin) {
}
}
func (gs *goldsmith) fault(s *stage, f *file, err error) {
log.Printf("%s\t%s\t%s", s.name, f.path, err)
gs.tainted = true
}
//
// Goldsmith Implementation
//
func (gs *goldsmith) Chain(p Plugin) Goldsmith {
go gs.chain(gs.newStage(), p)
go gs.chain(gs.newStage(p.Name()), p)
return gs
}
func (gs *goldsmith) Complete() bool {
s := gs.stages[len(gs.stages)-1]
for f := range s.output {
gs.exportFile(f)
}
gs.cleanupFiles()
tainted := gs.tainted
gs.stages = nil
gs.refs = nil
gs.tainted = false
return tainted
return gs.tainted
}
//
// Context Implementation
//
func (gs *goldsmith) NewFile(path string, data []byte) File {
atomic.AddInt64(&gs.active, 1)
return newFileFromData(path, data)

View File

@ -34,7 +34,12 @@ func New(srcDir, dstDir string) Goldsmith {
}
func NewThrottled(srcDir, dstDir string, targetFileCount uint) Goldsmith {
gs := &goldsmith{srcDir: srcDir, dstDir: dstDir}
gs := &goldsmith{
srcDir: srcDir,
dstDir: dstDir,
refs: make(map[string]bool),
}
gs.queueFiles(targetFileCount)
return gs
}