This commit is contained in:
Alex Yatskov 2023-12-10 09:51:46 -08:00
parent acc22a9b84
commit 2dd1fdbfa5
3 changed files with 14 additions and 43 deletions

View File

@ -45,25 +45,22 @@ func (self *fileExporter) Finalize(context *Context) error {
return nil return nil
} }
infoChan := make(chan fileInfo) return filepath.Walk(self.targetDir, func(path string, info os.FileInfo, err error) error {
go scanDir(self.targetDir, infoChan) if path == self.targetDir {
return nil
for info := range infoChan {
if info.path == self.targetDir {
continue
} }
relPath, err := filepath.Rel(self.targetDir, info.path) relPath, err := filepath.Rel(self.targetDir, path)
if err != nil { if err != nil {
panic(err) panic(err)
} }
if tokenized, _ := self.tokens[relPath]; !tokenized { if tokenized, _ := self.tokens[relPath]; !tokenized {
if err := os.RemoveAll(info.path); err != nil { if err := os.RemoveAll(path); err != nil {
return err return err
} }
} }
}
return nil return nil
})
} }

View File

@ -1,6 +1,7 @@
package goldsmith package goldsmith
import ( import (
"os"
"path/filepath" "path/filepath"
) )
@ -13,26 +14,22 @@ func (*fileImporter) Name() string {
} }
func (self *fileImporter) Initialize(context *Context) error { func (self *fileImporter) Initialize(context *Context) error {
infoChan := make(chan fileInfo) return filepath.Walk(self.sourceDir, func(path string, info os.FileInfo, err error) error {
go scanDir(self.sourceDir, infoChan)
for info := range infoChan {
if info.IsDir() { if info.IsDir() {
continue return nil
} }
relPath, err := filepath.Rel(self.sourceDir, info.path) relPath, err := filepath.Rel(self.sourceDir, path)
if err != nil { if err != nil {
panic(err) panic(err)
} }
file, err := context.CreateFileFromAsset(relPath, info.path) file, err := context.CreateFileFromAsset(relPath, path)
if err != nil { if err != nil {
return err return err
} }
context.DispatchFile(file) context.DispatchFile(file)
} return nil
})
return nil
} }

View File

@ -1,23 +0,0 @@
package goldsmith
import (
"os"
"path/filepath"
)
type fileInfo struct {
os.FileInfo
path string
}
func scanDir(dir string, infoChan chan fileInfo) {
defer close(infoChan)
filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err == nil {
infoChan <- fileInfo{FileInfo: info, path: path}
}
return err
})
}