Cleanup
This commit is contained in:
parent
ac600d147e
commit
c5f6bae50e
31
goldsmith.go
31
goldsmith.go
@ -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 == "." {
|
||||
|
17
stage.go
17
stage.go
@ -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 {
|
||||
|
12
types.go
12
types.go
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user