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 package goldsmith
import ( import (
"bytes"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -66,6 +67,7 @@ func (gs *goldsmith) scan(srcDir string) {
file := File{ file := File{
Path: relPath, Path: relPath,
Meta: make(map[string]interface{}), Meta: make(map[string]interface{}),
Buff: new(bytes.Buffer),
} }
var f *os.File 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 { if gs.err != nil {
return gs return gs
} }
if gs.err = ctx.Err; gs.err != nil { if gs.err = ctx.Err; gs.err == nil {
switch c := ctx.Chainer.(type) { switch c := ctx.Chainer.(type) {
case ChainerSingle: case ChainerSingle:
go gs.chainSingle(gs.makeStage(), c) go gs.chainSingle(gs.makeStage(), c)
@ -149,13 +151,13 @@ func (gs *goldsmith) Complete(dstDir string) ([]File, error) {
} }
var f *os.File 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()) _, file.Err = f.Write(file.Buff.Bytes())
f.Close() f.Close()
} }
} }
file.Buff.Reset() file.Buff = nil
files = append(files, file) files = append(files, file)
} }

View File

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