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:
parent
b8dae7a6e2
commit
b7713da70e
@ -52,24 +52,31 @@ func GetEmbedDetailsForFile(file *ast.File, baseDir string) []*EmbedDetails {
|
||||
for _, c := range comment.List {
|
||||
if strings.HasPrefix(c.Text, "//go:embed") {
|
||||
sl := strings.Split(c.Text, " ")
|
||||
path := ""
|
||||
all := false
|
||||
if len(sl) == 1 {
|
||||
continue
|
||||
}
|
||||
embedPath := strings.TrimSpace(sl[1])
|
||||
switch true {
|
||||
case strings.HasPrefix(embedPath, "all:"):
|
||||
path = strings.TrimPrefix(embedPath, "all:")
|
||||
all = true
|
||||
default:
|
||||
path = embedPath
|
||||
// support for multiple paths in one comment
|
||||
for _, arg := range sl[1:] {
|
||||
embedPath := strings.TrimSpace(arg)
|
||||
// ignores all pattern matching characters except escape sequence
|
||||
if strings.Contains(embedPath, "*") || strings.Contains(embedPath, "?") || strings.Contains(embedPath, "[") {
|
||||
continue
|
||||
}
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package staticanalysis
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetEmbedDetails(t *testing.T) {
|
||||
@ -25,6 +26,10 @@ func TestGetEmbedDetails(t *testing.T) {
|
||||
EmbedPath: "frontend/dist",
|
||||
All: true,
|
||||
},
|
||||
{
|
||||
EmbedPath: "frontend/static",
|
||||
All: false,
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
|
@ -8,9 +8,12 @@ import (
|
||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||
)
|
||||
|
||||
//go:embed all:frontend/dist
|
||||
//go:embed all:frontend/dist frontend/static
|
||||
var assets embed.FS
|
||||
|
||||
//go:embed frontend/src/*.json
|
||||
var srcjson embed.FS
|
||||
|
||||
func main() {
|
||||
// Create an instance of the app structure
|
||||
app := NewApp()
|
||||
|
@ -169,16 +169,19 @@ func CreateEmbedDirectories(cwd string, buildOptions *Options) error {
|
||||
|
||||
for _, embedDetail := range embedDetails {
|
||||
fullPath := embedDetail.GetFullPath()
|
||||
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
||||
err := os.MkdirAll(fullPath, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
// assumes path is directory only if it has no extension
|
||||
if filepath.Ext(fullPath) == "" {
|
||||
if _, err := os.Stat(fullPath); os.IsNotExist(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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### 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 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)
|
||||
|
Loading…
Reference in New Issue
Block a user