fix(internal/build): Using forward slash with embed fs

This commit is contained in:
Itamar 2023-06-11 10:26:33 +03:00
parent 4bd48fff60
commit 8e63d64f84
1 changed files with 44 additions and 20 deletions

View File

@ -4,6 +4,8 @@ import (
"bytes" "bytes"
"embed" "embed"
"fmt" "fmt"
"io"
"io/fs"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -286,34 +288,56 @@ func mergeI18nFiles(b *buildingMaterial) (err error) {
} }
func copyDirEntries(sourceFs embed.FS, sourceDir string, targetDir string) (err error) { func copyDirEntries(sourceFs embed.FS, sourceDir string, targetDir string) (err error) {
entries, err := ui.Build.ReadDir(sourceDir)
if err != nil {
return err
}
err = dir.CreateDirIfNotExist(targetDir) err = dir.CreateDirIfNotExist(targetDir)
if err != nil { if err != nil {
return err return err
} }
for _, entry := range entries { err = fs.WalkDir(sourceFs, sourceDir, func(path string, d fs.DirEntry, err error) error {
if entry.IsDir() {
err = copyDirEntries(sourceFs, filepath.Join(sourceDir, entry.Name()), filepath.Join(targetDir, entry.Name()))
if err != nil { if err != nil {
return err return err
} }
continue
} // Convert the path to use forward slashes, important because we use embedded FS which always uses forward slashes
file, err := sourceFs.ReadFile(filepath.Join(sourceDir, entry.Name())) path = filepath.ToSlash(path)
// Construct the absolute path for the source file/directory
srcPath := filepath.Join(sourceDir, path)
// Construct the absolute path for the destination file/directory
dstPath := filepath.Join(targetDir, path)
if d.IsDir() {
// Create the directory in the destination
err := os.MkdirAll(dstPath, d.Type())
if err != nil { if err != nil {
return err return err
} }
filename := filepath.Join(targetDir, entry.Name()) } else {
err = os.WriteFile(filename, file, 0666) // Open the source file
srcFile, err := sourceFs.Open(srcPath)
if err != nil {
return err
}
defer srcFile.Close()
// Create the destination file
dstFile, err := os.Create(dstPath)
if err != nil {
return err
}
defer dstFile.Close()
// Copy the file contents
_, err = io.Copy(dstFile, srcFile)
if err != nil { if err != nil {
return err return err
} }
} }
return nil return nil
})
return err
} }
func buildBinary(b *buildingMaterial) (err error) { func buildBinary(b *buildingMaterial) (err error) {