Skip to content

Commit f14ed9d

Browse files
authored
[state-hash] Change requests from previous PR (#1768)
## Summary I accidentally merged #1765 without committing the fixes requested in the PR. This PR contains them. ## How was it tested?
1 parent 4f50c91 commit f14ed9d

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

internal/lock/statehash.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ func UpdateAndSaveStateHashFile(args UpdateStateHashFileArgs) error {
4747
}
4848

4949
func isStateUpToDate(args UpdateStateHashFileArgs) (bool, error) {
50-
filesystemLock, err := readStateHashFile(args.ProjectDir)
50+
filesystemStateHash, err := readStateHashFile(args.ProjectDir)
5151
if err != nil {
5252
return false, err
5353
}
54-
newLock, err := getCurrentStateHash(args)
54+
newStateHash, err := getCurrentStateHash(args)
5555
if err != nil {
5656
return false, err
5757
}
5858

59-
return *filesystemLock == *newLock, nil
59+
return *filesystemStateHash == *newStateHash, nil
6060
}
6161

6262
func readStateHashFile(projectDir string) (*stateHashFile, error) {
63-
lockFile := &stateHashFile{}
64-
err := cuecfg.ParseFile(stateHashFilePath(projectDir), lockFile)
63+
hashFile := &stateHashFile{}
64+
err := cuecfg.ParseFile(stateHashFilePath(projectDir), hashFile)
6565
if errors.Is(err, fs.ErrNotExist) {
66-
return lockFile, nil
66+
return hashFile, nil
6767
}
6868
if err != nil {
6969
return nil, err
7070
}
71-
return lockFile, nil
71+
return hashFile, nil
7272
}
7373

7474
func getCurrentStateHash(args UpdateStateHashFileArgs) (*stateHashFile, error) {
@@ -100,7 +100,7 @@ func getCurrentStateHash(args UpdateStateHashFileArgs) (*stateHashFile, error) {
100100
}
101101

102102
func stateHashFilePath(projectDir string) string {
103-
return filepath.Join(projectDir, ".devbox", "local.lock")
103+
return filepath.Join(projectDir, ".devbox", "state.json")
104104
}
105105

106106
func manifestHash(profileDir string) (string, error) {

internal/shellgen/scripts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ func writeInitHookFile(devbox devboxer, body, tmpl, filename string) (err error)
110110
}
111111
defer script.Close() // best effort: close file
112112

113+
// skip adding init-hook recursion guard for the
114+
// default hook or any empty hook
115+
// there's nothing to guard, and it introduces complexity
113116
if body == devconfig.DefaultInitHook || strings.TrimSpace(body) == "" {
114117
_, err = script.WriteString(body)
115118
return errors.WithStack(err)

internal/shellgen/tmpl/init-hook-fish.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
{{/* Fish version */ -}}
2-
{{/* if hash is set, we're in recursive loop, just exit */ -}}
1+
{{/*
2+
Fish version
3+
Note: This template is not used if init hook is empty or default
4+
5+
If hash is set, we're in recursive loop, just exit
6+
*/ -}}
37

48
if set -q {{ .InitHookHash }}; then
59
exit 0

internal/shellgen/tmpl/init-hook.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
{{/*
2+
Note: This template is not used if init hook is empty or default
13

2-
{{/* if hash is set, we're in recursive loop, just exit */ -}}
4+
If hash is set, we're in recursive loop, just exit
5+
*/ -}}
36

47
if [ -n "${{ .InitHookHash }}" ]; then
58
return

0 commit comments

Comments
 (0)