From beb43687df83ed3d3c7624e6b65eea93abd90b3b Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Jan 2016 13:12:50 +0900 Subject: [PATCH] Cleanup plugin interface --- context.go | 4 ---- core.go | 26 ++++++++------------------ file.go | 4 +++- goldsmith.go | 1 - 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/context.go b/context.go index f85eec5..2e7879c 100644 --- a/context.go +++ b/context.go @@ -87,10 +87,6 @@ func (ctx *context) DispatchFile(f File) { ctx.output <- f.(*file) } -func (ctx *context) ReferenceFile(path string) { - ctx.gs.referenceFile(path) -} - func (ctx *context) SrcDir() string { return ctx.gs.srcDir } diff --git a/core.go b/core.go index 198986c..9288239 100644 --- a/core.go +++ b/core.go @@ -31,9 +31,7 @@ import ( type goldsmith struct { srcDir, dstDir string contexts []*context - - refs map[string]bool - refMtx sync.Mutex + refs map[string]bool errors []error errorMtx sync.Mutex @@ -90,29 +88,21 @@ func (gs *goldsmith) cleanupFiles() { } func (gs *goldsmith) exportFile(f *file) error { - absPath := filepath.Join(gs.dstDir, f.path) - if err := f.export(absPath); err != nil { + if err := f.export(gs.dstDir); err != nil { return err } - gs.referenceFile(f.path) - return nil -} - -func (gs *goldsmith) referenceFile(path string) { - gs.refMtx.Lock() - defer gs.refMtx.Unlock() - - path = cleanPath(path) - + pathSeg := cleanPath(f.path) for { - gs.refs[path] = true - if path == "." { + gs.refs[pathSeg] = true + if pathSeg == "." { break } - path = filepath.Dir(path) + pathSeg = filepath.Dir(pathSeg) } + + return nil } func (gs *goldsmith) fault(f *file, err error) { diff --git a/file.go b/file.go index d7af136..b1984ab 100644 --- a/file.go +++ b/file.go @@ -28,6 +28,7 @@ import ( "io/ioutil" "os" "path" + "path/filepath" ) type file struct { @@ -38,7 +39,8 @@ type file struct { asset string } -func (f *file) export(dstPath string) error { +func (f *file) export(dstDir string) error { + dstPath := filepath.Join(dstDir, f.path) if len(f.asset) > 0 && fileCached(f.asset, dstPath) { return nil } diff --git a/goldsmith.go b/goldsmith.go index 7d702c2..7d5d927 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -68,7 +68,6 @@ func NewFileFromAsset(path, asset string) File { type Context interface { DispatchFile(f File) - ReferenceFile(path string) SrcDir() string DstDir() string