From 78eed4c9b1bc503527c03f981df66275d967c1bb Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Mon, 3 Jun 2024 22:47:24 +0200 Subject: [PATCH] Local instance state dir --- pkg/instance.go | 2 +- pkg/local_instance.go | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/instance.go b/pkg/instance.go index c59d136c..40a81891 100644 --- a/pkg/instance.go +++ b/pkg/instance.go @@ -341,7 +341,7 @@ func (i Instance) CacheDir() string { func (i Instance) LockDir() string { if i.IsLocal() { - return i.local.LockDir() + return i.local.StateDir() } return i.CacheDir() } diff --git a/pkg/local_instance.go b/pkg/local_instance.go index 6e2b8fc4..461d7314 100644 --- a/pkg/local_instance.go +++ b/pkg/local_instance.go @@ -137,8 +137,15 @@ func (li LocalInstance) overrideDirsChecksum() (string, error) { return filex.ChecksumPaths(lo.Filter(li.OverrideDirs(), func(d string, _ int) bool { return pathx.Exists(d) }), []string{}) } -func (li LocalInstance) LockDir() string { - return pathx.Canonical(fmt.Sprintf("%s/%s/lock", li.WorkDir(), common.VarDirName)) +func (li LocalInstance) StateDir() string { + oldDir := pathx.Canonical(fmt.Sprintf("%s/%s/lock", li.WorkDir(), common.VarDirName)) + newDir := pathx.Canonical(fmt.Sprintf("%s/%s/state", li.WorkDir(), common.VarDirName)) + if pathx.Exists(oldDir) && !pathx.Exists(newDir) { + if err := os.Rename(oldDir, newDir); err != nil { + log.Fatalf("%s > cannot migrate state dir from '%s' to '%s': %s", li.instance.IDColor(), oldDir, newDir, err) + } + } + return newDir } func (li LocalInstance) QuickstartDir() string { @@ -248,7 +255,7 @@ func (li LocalInstance) Import() error { } func (li LocalInstance) createLock() osx.Lock[localInstanceCreateLock] { - return osx.NewLock(fmt.Sprintf("%s/create.yml", li.LockDir()), func() (localInstanceCreateLock, error) { + return osx.NewLock(fmt.Sprintf("%s/create.yml", li.StateDir()), func() (localInstanceCreateLock, error) { var zero localInstanceCreateLock jar, err := li.LocalOpts().Jar() if err != nil { @@ -344,7 +351,7 @@ func (li LocalInstance) IsCreated() bool { } func (li LocalInstance) initLock() osx.Lock[localInstanceInitLock] { - return osx.NewLock(fmt.Sprintf("%s/init.yml", li.LockDir()), func() (localInstanceInitLock, error) { + return osx.NewLock(fmt.Sprintf("%s/init.yml", li.StateDir()), func() (localInstanceInitLock, error) { return localInstanceInitLock{Initialized: true}, nil }) } @@ -517,7 +524,7 @@ func (li LocalInstance) CheckPortsOpen() error { } func (li LocalInstance) updateLock() osx.Lock[localInstanceUpdateLock] { - return osx.NewLock(fmt.Sprintf("%s/start.yml", li.LockDir()), func() (localInstanceUpdateLock, error) { + return osx.NewLock(fmt.Sprintf("%s/start.yml", li.StateDir()), func() (localInstanceUpdateLock, error) { var zero localInstanceUpdateLock overrides, err := li.overrideDirsChecksum() if err != nil {