This commit is contained in:
Alex Yatskov 2015-12-17 13:06:44 +09:00
parent ac600d147e
commit c5f6bae50e
3 changed files with 22 additions and 38 deletions

View File

@ -39,17 +39,15 @@ type goldsmith struct {
srcDir, dstDir string
stages []*stage
refs map[string]bool
}
func newFile(path string) *File {
return &File{
Path: cleanPath(path),
Meta: make(map[string]interface{}),
}
mtx sync.Mutex
}
func New(srcDir, dstDir string) Goldsmith {
gs := &goldsmith{srcDir: srcDir, dstDir: dstDir}
gs := &goldsmith{
srcDir: srcDir,
dstDir: dstDir,
}
gs.queueFiles()
return gs
}
@ -83,8 +81,11 @@ func (gs *goldsmith) queueFiles() {
}
func (gs *goldsmith) cleanupFiles() {
files := make(chan string)
dirs := make(chan string)
var (
files = make(chan string)
dirs = make(chan string)
)
go scanDir(gs.dstDir, files, dirs)
for files != nil || dirs != nil {
@ -126,11 +127,6 @@ func (gs *goldsmith) exportFile(file *File) {
return
}
if file.Type == FileReference {
gs.refFile(file.Path)
return
}
absPath := filepath.Join(gs.dstDir, file.Path)
if file.Err = os.MkdirAll(path.Dir(absPath), 0755); file.Err != nil {
return
@ -192,12 +188,15 @@ func (gs *goldsmith) chain(s *stage, p Plugin) {
}
func (gs *goldsmith) refFile(path string) {
path = cleanPath(path)
gs.mtx.Lock()
defer gs.mtx.Unlock()
if gs.refs == nil {
gs.refs = make(map[string]bool)
}
path = cleanPath(path)
for {
gs.refs[path] = true
if path == "." {

View File

@ -23,21 +23,16 @@
package goldsmith
func (s *stage) NewFile(path string) *File {
file := newFile(path)
file := &File{
Path: cleanPath(path),
Meta: make(map[string]interface{}),
}
s.output <- file
return file
}
func (s *stage) NewFileStatic(path string) *File {
file := s.NewFile(path)
file.Type = FileStatic
return file
}
func (s *stage) NewFileRef(path string) *File {
file := s.NewFile(path)
file.Type = FileReference
return file
func (s *stage) RefFile(path string) {
s.gs.refFile(path)
}
func (s *stage) SrcDir() string {

View File

@ -47,20 +47,11 @@ type Chainer interface {
Chain(ctx Context, input, output chan *File)
}
type FileType int
const (
FileNormal FileType = iota
FileStatic
FileReference
)
type File struct {
Path string
Meta map[string]interface{}
Buff bytes.Buffer
Err error
Type FileType
}
type Context interface {
@ -68,6 +59,5 @@ type Context interface {
DstDir() string
NewFile(path string) *File
NewFileStatic(path string) *File
NewFileRef(path string) *File
RefFile(path string)
}