WIP
This commit is contained in:
parent
72347cf724
commit
b33e6b7230
9
file.go
9
file.go
@ -31,9 +31,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type file struct {
|
type file struct {
|
||||||
path string
|
path string
|
||||||
meta map[string]interface{}
|
meta map[string]interface{}
|
||||||
|
|
||||||
srcData *bytes.Reader
|
srcData *bytes.Reader
|
||||||
srcPath string
|
srcPath string
|
||||||
}
|
}
|
||||||
@ -108,6 +107,10 @@ func (f *file) cache() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// File Implementation
|
||||||
|
//
|
||||||
|
|
||||||
func (f *file) Path() string {
|
func (f *file) Path() string {
|
||||||
return f.path
|
return f.path
|
||||||
}
|
}
|
||||||
|
43
goldsmith.go
43
goldsmith.go
@ -32,29 +32,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type stage struct {
|
type stage struct {
|
||||||
|
name string
|
||||||
input, output chan *file
|
input, output chan *file
|
||||||
}
|
}
|
||||||
|
|
||||||
type goldsmith struct {
|
type goldsmith struct {
|
||||||
srcDir, dstDir string
|
srcDir, dstDir string
|
||||||
stages []*stage
|
|
||||||
refs map[string]bool
|
refs map[string]bool
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
|
stages []*stage
|
||||||
active int64
|
active int64
|
||||||
stalled int64
|
stalled int64
|
||||||
tainted bool
|
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) {
|
func (gs *goldsmith) queueFiles(target uint) {
|
||||||
files := make(chan string)
|
files := make(chan string)
|
||||||
go scanDir(gs.srcDir, files, nil)
|
go scanDir(gs.srcDir, files, nil)
|
||||||
|
|
||||||
s := gs.newStage()
|
s := gs.newStage("Goldsmith")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(s.output)
|
defer close(s.output)
|
||||||
@ -132,8 +128,12 @@ func (gs *goldsmith) exportFile(f *file) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *goldsmith) newStage() *stage {
|
func (gs *goldsmith) newStage(name string) *stage {
|
||||||
s := &stage{output: make(chan *file)}
|
s := &stage{
|
||||||
|
name: name,
|
||||||
|
output: make(chan *file),
|
||||||
|
}
|
||||||
|
|
||||||
if len(gs.stages) > 0 {
|
if len(gs.stages) > 0 {
|
||||||
s.input = gs.stages[len(gs.stages)-1].output
|
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 {
|
func (gs *goldsmith) Chain(p Plugin) Goldsmith {
|
||||||
go gs.chain(gs.newStage(), p)
|
go gs.chain(gs.newStage(p.Name()), p)
|
||||||
return gs
|
return gs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gs *goldsmith) Complete() bool {
|
func (gs *goldsmith) Complete() bool {
|
||||||
s := gs.stages[len(gs.stages)-1]
|
s := gs.stages[len(gs.stages)-1]
|
||||||
|
|
||||||
for f := range s.output {
|
for f := range s.output {
|
||||||
gs.exportFile(f)
|
gs.exportFile(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
gs.cleanupFiles()
|
gs.cleanupFiles()
|
||||||
|
return gs.tainted
|
||||||
tainted := gs.tainted
|
|
||||||
|
|
||||||
gs.stages = nil
|
|
||||||
gs.refs = nil
|
|
||||||
gs.tainted = false
|
|
||||||
|
|
||||||
return tainted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Context Implementation
|
||||||
|
//
|
||||||
|
|
||||||
func (gs *goldsmith) NewFile(path string, data []byte) File {
|
func (gs *goldsmith) NewFile(path string, data []byte) File {
|
||||||
atomic.AddInt64(&gs.active, 1)
|
atomic.AddInt64(&gs.active, 1)
|
||||||
return newFileFromData(path, data)
|
return newFileFromData(path, data)
|
||||||
|
7
types.go
7
types.go
@ -34,7 +34,12 @@ func New(srcDir, dstDir string) Goldsmith {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewThrottled(srcDir, dstDir string, targetFileCount uint) 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)
|
gs.queueFiles(targetFileCount)
|
||||||
return gs
|
return gs
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user