Skip to content

Commit

Permalink
lxd/db/schema/update: Fix to support lxd in non-GOPATH locations
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Parrott <[email protected]>
  • Loading branch information
tomponline committed Dec 20, 2024
1 parent 1054c60 commit 42b8351
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lxd/db/schema/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"runtime"
"strings"

Expand Down Expand Up @@ -40,9 +39,9 @@ func DotGo(updates map[int]Update, name string) error {
// Passing 1 to runtime.Caller identifies our caller.
_, filename, _, _ := runtime.Caller(1)

// runtime.Caller returns the path after "${GOPATH}/src" when used with `go generate`.
// runtime.Caller returns source file name without full path. Translate into relative path to source file.
if strings.HasPrefix(filename, "github.com") {
filename = filepath.Join(os.Getenv("GOPATH"), "src", filename)
filename = strings.TrimPrefix(filename, "github.com/canonical/lxd/lxd/db/")
}

file, err := os.Create(path.Join(path.Dir(filename), name+".go"))
Expand Down

0 comments on commit 42b8351

Please sign in to comment.