From 394982f9e90bbe32fd8c7c02e9d8324bb57837de Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 11 Nov 2015 22:57:49 +0900 Subject: [PATCH] Reset state --- goldsmith.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/goldsmith.go b/goldsmith.go index cac08a6..2dc9573 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -45,13 +45,8 @@ type goldsmith struct { } func New(srcDir, dstDir string) Goldsmith { - gs := &goldsmith{ - srcDir: srcDir, - dstDir: dstDir, - refs: make(map[string]bool), - } - - gs.scanFs() + gs := &goldsmith{srcDir: srcDir, dstDir: dstDir} + gs.queueFiles() return gs } @@ -74,7 +69,7 @@ func NewFileRef(path string) *File { return file } -func (gs *goldsmith) scanFs() { +func (gs *goldsmith) queueFiles() { files := make(chan string) go scanDir(gs.srcDir, files, nil) @@ -217,6 +212,10 @@ func (gs *goldsmith) chain(s stage, c Chainer) { func (gs *goldsmith) refFile(path string) { path = cleanPath(path) + if gs.refs == nil { + gs.refs = make(map[string]bool) + } + for { gs.refs[path] = true if path == "." { @@ -264,7 +263,13 @@ func (gs *goldsmith) Complete() ([]*File, error) { gs.cleanupFiles() } - return files, gs.err + err := gs.err + + gs.stages = nil + gs.refs = nil + gs.err = nil + + return files, err } func cleanPath(path string) string {