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)
}
func (ctx *context) ReferenceFile(path string) {
ctx.gs.referenceFile(path)
}
func (ctx *context) SrcDir() string {
return ctx.gs.srcDir
}

26
core.go
View File

@ -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) {

View File

@ -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
}

View File

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