Skip to content

Commit

Permalink
Merge pull request #259 from wttech/local-instance-state-dir
Browse files Browse the repository at this point in the history
Local instance state dir
  • Loading branch information
krystian-panek-vmltech authored Jun 4, 2024
2 parents b56ad56 + 78eed4c commit 387fdb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
17 changes: 12 additions & 5 deletions pkg/local_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 387fdb0

Please sign in to comment.