Skip to content

Commit 8b6be0b

Browse files
authored
Fix script gen clean up failure (#1252)
## Summary Getting the following error when running any script ``` [DEBUG] 2023/07/05 21:06:23 go.jetpack.io/devbox/internal/shellgen/scripts.go:73: failed to clean up script file build.sh, error = remove ~/devbox/.devbox/gen/scripts/build.sh.sh: no such file or directory ``` It looks like `.sh` is wrongly appended to the existing files under the scripts directory. This PR fixes that. ## How was it tested? devbox run build
1 parent 8d7d6ca commit 8b6be0b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/shellgen/scripts.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,22 @@ func WriteScriptsToFiles(devbox devboxer) error {
5454
if err != nil {
5555
return errors.WithStack(err)
5656
}
57-
written[ScriptPath(devbox.ProjectDir(), HooksFilename)] = struct{}{}
57+
written[HooksFilename] = struct{}{}
5858

5959
// Write scripts to files.
6060
for name, body := range devbox.Config().Scripts() {
6161
err = WriteScriptFile(devbox, name, ScriptBody(devbox, body.String()))
6262
if err != nil {
6363
return errors.WithStack(err)
6464
}
65-
written[ScriptPath(devbox.ProjectDir(), name)] = struct{}{}
65+
written[name] = struct{}{}
6666
}
6767

6868
// Delete any files that weren't written just now.
6969
for _, entry := range entries {
70-
if _, ok := written[entry.Name()]; !ok && !entry.IsDir() {
71-
err := os.Remove(ScriptPath(devbox.ProjectDir(), entry.Name()))
70+
scriptName := strings.TrimSuffix(entry.Name(), ".sh")
71+
if _, ok := written[scriptName]; !ok && !entry.IsDir() {
72+
err := os.Remove(ScriptPath(devbox.ProjectDir(), scriptName))
7273
if err != nil {
7374
debug.Log("failed to clean up script file %s, error = %s", entry.Name(), err) // no need to fail run
7475
}

0 commit comments

Comments
 (0)