This commit is contained in:
Alex Yatskov 2015-11-01 17:06:15 +09:00
parent fa571ba089
commit 8738157703
2 changed files with 8 additions and 6 deletions

View File

@ -23,6 +23,7 @@
package goldsmith
import (
"bytes"
"os"
"path"
"path/filepath"
@ -66,6 +67,7 @@ func (gs *goldsmith) scan(srcDir string) {
file := File{
Path: relPath,
Meta: make(map[string]interface{}),
Buff: new(bytes.Buffer),
}
var f *os.File
@ -120,12 +122,12 @@ func (gs *goldsmith) chainMultiple(s stage, cm ChainerMultiple) {
}
}
func (gs *goldsmith) Chain(ctx *Context) Goldsmith {
func (gs *goldsmith) Chain(ctx Context) Goldsmith {
if gs.err != nil {
return gs
}
if gs.err = ctx.Err; gs.err != nil {
if gs.err = ctx.Err; gs.err == nil {
switch c := ctx.Chainer.(type) {
case ChainerSingle:
go gs.chainSingle(gs.makeStage(), c)
@ -149,13 +151,13 @@ func (gs *goldsmith) Complete(dstDir string) ([]File, error) {
}
var f *os.File
if f, file.Err = os.Create(absPath); f == nil {
if f, file.Err = os.Create(absPath); file.Err == nil {
_, file.Err = f.Write(file.Buff.Bytes())
f.Close()
}
}
file.Buff.Reset()
file.Buff = nil
files = append(files, file)
}

View File

@ -25,7 +25,7 @@ package goldsmith
import "bytes"
type Goldsmith interface {
Chain(ctx *Context) Goldsmith
Chain(ctx Context) Goldsmith
Complete(dstDir string) ([]File, error)
}
@ -40,7 +40,7 @@ type ChainerMultiple interface {
type File struct {
Path string
Meta map[string]interface{}
Buff bytes.Buffer
Buff *bytes.Buffer
Err error
}