diff --git a/internal/lock/statehash.go b/internal/lock/statehash.go index b0cd4eecf6e..ed3ee8a1e7a 100644 --- a/internal/lock/statehash.go +++ b/internal/lock/statehash.go @@ -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) { @@ -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) { diff --git a/internal/shellgen/scripts.go b/internal/shellgen/scripts.go index 3853d8b7be5..8cb2e98f634 100644 --- a/internal/shellgen/scripts.go +++ b/internal/shellgen/scripts.go @@ -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) diff --git a/internal/shellgen/tmpl/init-hook-fish.tmpl b/internal/shellgen/tmpl/init-hook-fish.tmpl index ca223541218..18b0ab994a1 100644 --- a/internal/shellgen/tmpl/init-hook-fish.tmpl +++ b/internal/shellgen/tmpl/init-hook-fish.tmpl @@ -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 diff --git a/internal/shellgen/tmpl/init-hook.tmpl b/internal/shellgen/tmpl/init-hook.tmpl index 57e677c3438..052a0202c21 100644 --- a/internal/shellgen/tmpl/init-hook.tmpl +++ b/internal/shellgen/tmpl/init-hook.tmpl @@ -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