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

View File

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

View File

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