From 27fb41bec3ff3c548fb2914820a4a9b8cd15f362 Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Fri, 20 Dec 2024 08:49:53 +0000 Subject: [PATCH] lxd/db/schema/update: Fix to support lxd in non-GOPATH locations Signed-off-by: Thomas Parrott --- lxd/db/schema/update.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lxd/db/schema/update.go b/lxd/db/schema/update.go index f3142774ec21..4c4d6e01c26d 100644 --- a/lxd/db/schema/update.go +++ b/lxd/db/schema/update.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "path" - "path/filepath" "runtime" "strings" @@ -40,9 +39,10 @@ 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 path starting from github.com. + // 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"))