Skip to content

Commit

Permalink
Fix file access for embedded files on windows (#103)
Browse files Browse the repository at this point in the history
Windows uses '\' as path separator, while Linux uses '/'. However, Go's embed file system uses '/' on all platforms.
  • Loading branch information
minhnhatnoe authored Jun 10, 2023
1 parent 3159665 commit aa5d111
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions db/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"database/sql"
"io/fs"
"log"
"path/filepath"
"path"
"regexp"
"sort"

Expand Down Expand Up @@ -44,7 +44,7 @@ func (db *DB) migrate() error {

// Do migrations one by one
for _, name := range versions {
sqlFile := filepath.Join(assetsSql, name+".sql")
sqlFile := path.Join(assetsSql, name+".sql")
file, err := fs.ReadFile(embed.Content, sqlFile)
if err != nil {
return errors.Wrapf(err, "File %s", sqlFile)
Expand Down
5 changes: 5 additions & 0 deletions embed/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Package embed puts all files in embed/assets and embed/templates
// into the executable.
// While the embed file system is cross-platform, it always exposes a
// '/'-delimited file system.
package embed
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.0
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/net v0.7.0
golang.org/x/net v0.7.0 // indirect
golang.org/x/text v0.7.0
golang.org/x/tools v0.1.12
google.golang.org/appengine v1.6.5 // indirect
Expand Down
8 changes: 8 additions & 0 deletions scripts/windows/production_test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ErrorActionPreference = "Stop"
Remove-Item kjudge.db*

& "scripts\windows\production_build.ps1"

Invoke-Expression ".\kjudge $args"

# pwsh -c scripts/windows/production_test.ps1 --sandbox=raw to run this test script

0 comments on commit aa5d111

Please sign in to comment.