5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 11:10:47 +08:00

Fixed an issue where go:embed directives would generate illegal directories (#3445)

* Update staticanalysis.go and associated tests

* Update changelog

* Changed format of octal literal

* Update changelog
This commit is contained in:
Leo 2024-05-02 07:40:38 -04:00 committed by GitHub
parent b8dae7a6e2
commit b7713da70e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 44 additions and 25 deletions

View File

@ -52,24 +52,31 @@ func GetEmbedDetailsForFile(file *ast.File, baseDir string) []*EmbedDetails {
for _, c := range comment.List { for _, c := range comment.List {
if strings.HasPrefix(c.Text, "//go:embed") { if strings.HasPrefix(c.Text, "//go:embed") {
sl := strings.Split(c.Text, " ") sl := strings.Split(c.Text, " ")
path := ""
all := false
if len(sl) == 1 { if len(sl) == 1 {
continue continue
} }
embedPath := strings.TrimSpace(sl[1]) // support for multiple paths in one comment
switch true { for _, arg := range sl[1:] {
case strings.HasPrefix(embedPath, "all:"): embedPath := strings.TrimSpace(arg)
path = strings.TrimPrefix(embedPath, "all:") // ignores all pattern matching characters except escape sequence
all = true if strings.Contains(embedPath, "*") || strings.Contains(embedPath, "?") || strings.Contains(embedPath, "[") {
default: continue
path = embedPath }
if strings.HasPrefix(embedPath, "all:") {
result = append(result, &EmbedDetails{
EmbedPath: strings.TrimPrefix(embedPath, "all:"),
All: true,
BaseDir: baseDir,
})
} else {
result = append(result, &EmbedDetails{
EmbedPath: embedPath,
All: false,
BaseDir: baseDir,
})
}
} }
result = append(result, &EmbedDetails{
EmbedPath: path,
All: all,
BaseDir: baseDir,
})
} }
} }
} }

View File

@ -1,8 +1,9 @@
package staticanalysis package staticanalysis
import ( import (
"github.com/stretchr/testify/require"
"testing" "testing"
"github.com/stretchr/testify/require"
) )
func TestGetEmbedDetails(t *testing.T) { func TestGetEmbedDetails(t *testing.T) {
@ -25,6 +26,10 @@ func TestGetEmbedDetails(t *testing.T) {
EmbedPath: "frontend/dist", EmbedPath: "frontend/dist",
All: true, All: true,
}, },
{
EmbedPath: "frontend/static",
All: false,
},
}, },
wantErr: false, wantErr: false,
}, },

View File

@ -8,9 +8,12 @@ import (
"github.com/wailsapp/wails/v2/pkg/options/assetserver" "github.com/wailsapp/wails/v2/pkg/options/assetserver"
) )
//go:embed all:frontend/dist //go:embed all:frontend/dist frontend/static
var assets embed.FS var assets embed.FS
//go:embed frontend/src/*.json
var srcjson embed.FS
func main() { func main() {
// Create an instance of the app structure // Create an instance of the app structure
app := NewApp() app := NewApp()

View File

@ -169,16 +169,19 @@ func CreateEmbedDirectories(cwd string, buildOptions *Options) error {
for _, embedDetail := range embedDetails { for _, embedDetail := range embedDetails {
fullPath := embedDetail.GetFullPath() fullPath := embedDetail.GetFullPath()
if _, err := os.Stat(fullPath); os.IsNotExist(err) { // assumes path is directory only if it has no extension
err := os.MkdirAll(fullPath, 0o755) if filepath.Ext(fullPath) == "" {
if err != nil { if _, err := os.Stat(fullPath); os.IsNotExist(err) {
return err err := os.MkdirAll(fullPath, 0o755)
if err != nil {
return err
}
f, err := os.Create(filepath.Join(fullPath, "gitkeep"))
if err != nil {
return err
}
_ = f.Close()
} }
f, err := os.Create(filepath.Join(fullPath, "gitkeep"))
if err != nil {
return err
}
_ = f.Close()
} }
} }

View File

@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed an issue where embed directives with patterned paths would create illegal directories. Changed by [@twonull](https://github.com/twonull) in [PR](https://github.com/wailsapp/wails/pull/3445)
- Fixed an issue where certain calls to createFrom in TypeScript would fail. Changed by [@twonull](https://github.com/twonull) in [PR](https://github.com/wailsapp/wails/pull/3435) - Fixed an issue where certain calls to createFrom in TypeScript would fail. Changed by [@twonull](https://github.com/twonull) in [PR](https://github.com/wailsapp/wails/pull/3435)
- Fixed some typos in comments. Changed by [@reallylowest](https://github.com/reallylowest) in [PR](https://github.com/wailsapp/wails/pull/3357) - Fixed some typos in comments. Changed by [@reallylowest](https://github.com/reallylowest) in [PR](https://github.com/wailsapp/wails/pull/3357)
- Fixed an issue where the destination file was not properly closed after copying. Changed by [@testwill](https://github.com/testwill) in [PR](https://github.com/wailsapp/wails/pull/3384) - Fixed an issue where the destination file was not properly closed after copying. Changed by [@testwill](https://github.com/testwill) in [PR](https://github.com/wailsapp/wails/pull/3384)