Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local instance state dir #259

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading