Cleanup plugin interface

This commit is contained in:
Alex Yatskov 2016-01-13 13:12:50 +09:00
parent 95079bca8e
commit beb43687df
4 changed files with 11 additions and 24 deletions

View File

@ -87,10 +87,6 @@ func (ctx *context) DispatchFile(f File) {
ctx.output <- f.(*file) ctx.output <- f.(*file)
} }
func (ctx *context) ReferenceFile(path string) {
ctx.gs.referenceFile(path)
}
func (ctx *context) SrcDir() string { func (ctx *context) SrcDir() string {
return ctx.gs.srcDir return ctx.gs.srcDir
} }

24
core.go
View File

@ -31,9 +31,7 @@ import (
type goldsmith struct { type goldsmith struct {
srcDir, dstDir string srcDir, dstDir string
contexts []*context contexts []*context
refs map[string]bool refs map[string]bool
refMtx sync.Mutex
errors []error errors []error
errorMtx sync.Mutex errorMtx sync.Mutex
@ -90,29 +88,21 @@ func (gs *goldsmith) cleanupFiles() {
} }
func (gs *goldsmith) exportFile(f *file) error { func (gs *goldsmith) exportFile(f *file) error {
absPath := filepath.Join(gs.dstDir, f.path) if err := f.export(gs.dstDir); err != nil {
if err := f.export(absPath); err != nil {
return err return err
} }
gs.referenceFile(f.path) pathSeg := cleanPath(f.path)
return nil
}
func (gs *goldsmith) referenceFile(path string) {
gs.refMtx.Lock()
defer gs.refMtx.Unlock()
path = cleanPath(path)
for { for {
gs.refs[path] = true gs.refs[pathSeg] = true
if path == "." { if pathSeg == "." {
break break
} }
path = filepath.Dir(path) pathSeg = filepath.Dir(pathSeg)
} }
return nil
} }
func (gs *goldsmith) fault(f *file, err error) { func (gs *goldsmith) fault(f *file, err error) {

View File

@ -28,6 +28,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"path/filepath"
) )
type file struct { type file struct {
@ -38,7 +39,8 @@ type file struct {
asset string 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) { if len(f.asset) > 0 && fileCached(f.asset, dstPath) {
return nil return nil
} }

View File

@ -68,7 +68,6 @@ func NewFileFromAsset(path, asset string) File {
type Context interface { type Context interface {
DispatchFile(f File) DispatchFile(f File)
ReferenceFile(path string)
SrcDir() string SrcDir() string
DstDir() string DstDir() string