From 972c4d81f515240816595c8762012ddc1935b20e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 10 Dec 2023 09:51:46 -0800 Subject: [PATCH] Cleanup --- file_exporter.go | 17 +++++++---------- file_importer.go | 17 +++++++---------- file_util.go | 23 ----------------------- 3 files changed, 14 insertions(+), 43 deletions(-) delete mode 100644 file_util.go diff --git a/file_exporter.go b/file_exporter.go index e321f7c..bc9f468 100644 --- a/file_exporter.go +++ b/file_exporter.go @@ -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 + }) } diff --git a/file_importer.go b/file_importer.go index a110a97..9c4864f 100644 --- a/file_importer.go +++ b/file_importer.go @@ -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 + }) } diff --git a/file_util.go b/file_util.go deleted file mode 100644 index 7ffb578..0000000 --- a/file_util.go +++ /dev/null @@ -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 - }) -}