Skip to content

[state-hash] Change requests from previous PR #1768

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

Merged
merged 1 commit into from
Feb 1, 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
16 changes: 8 additions & 8 deletions internal/lock/statehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ func UpdateAndSaveStateHashFile(args UpdateStateHashFileArgs) error {
}

func isStateUpToDate(args UpdateStateHashFileArgs) (bool, error) {
filesystemLock, err := readStateHashFile(args.ProjectDir)
filesystemStateHash, err := readStateHashFile(args.ProjectDir)
if err != nil {
return false, err
}
newLock, err := getCurrentStateHash(args)
newStateHash, err := getCurrentStateHash(args)
if err != nil {
return false, err
}

return *filesystemLock == *newLock, nil
return *filesystemStateHash == *newStateHash, nil
}

func readStateHashFile(projectDir string) (*stateHashFile, error) {
lockFile := &stateHashFile{}
err := cuecfg.ParseFile(stateHashFilePath(projectDir), lockFile)
hashFile := &stateHashFile{}
err := cuecfg.ParseFile(stateHashFilePath(projectDir), hashFile)
if errors.Is(err, fs.ErrNotExist) {
return lockFile, nil
return hashFile, nil
}
if err != nil {
return nil, err
}
return lockFile, nil
return hashFile, nil
}

func getCurrentStateHash(args UpdateStateHashFileArgs) (*stateHashFile, error) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func getCurrentStateHash(args UpdateStateHashFileArgs) (*stateHashFile, error) {
}

func stateHashFilePath(projectDir string) string {
return filepath.Join(projectDir, ".devbox", "local.lock")
return filepath.Join(projectDir, ".devbox", "state.json")
}

func manifestHash(profileDir string) (string, error) {
Expand Down
3 changes: 3 additions & 0 deletions internal/shellgen/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func writeInitHookFile(devbox devboxer, body, tmpl, filename string) (err error)
}
defer script.Close() // best effort: close file

// skip adding init-hook recursion guard for the
// default hook or any empty hook
// there's nothing to guard, and it introduces complexity
if body == devconfig.DefaultInitHook || strings.TrimSpace(body) == "" {
_, err = script.WriteString(body)
return errors.WithStack(err)
Expand Down
8 changes: 6 additions & 2 deletions internal/shellgen/tmpl/init-hook-fish.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{/* Fish version */ -}}
{{/* if hash is set, we're in recursive loop, just exit */ -}}
{{/*
Fish version
Note: This template is not used if init hook is empty or default

If hash is set, we're in recursive loop, just exit
*/ -}}

if set -q {{ .InitHookHash }}; then
exit 0
Expand Down
5 changes: 4 additions & 1 deletion internal/shellgen/tmpl/init-hook.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{{/*
Note: This template is not used if init hook is empty or default

{{/* if hash is set, we're in recursive loop, just exit */ -}}
If hash is set, we're in recursive loop, just exit
*/ -}}

if [ -n "${{ .InitHookHash }}" ]; then
return
Expand Down