Skip to content

Commit 28cb879

Browse files
authored
Merge pull request #13 from AkihiroSuda/a
fix state dir clean-up
2 parents 3625074 + 33d8261 commit 28cb879

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/parent/parent.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ func Parent(pipeFDEnvKey string, opt *Opt) error {
6868
}
6969
defer os.RemoveAll(opt.StateDir)
7070
defer lock.Unlock()
71+
// when the previous execution crashed, the state dir may not be removed successfully.
72+
// explicitly remove everything in the state dir except the lock file here.
73+
for _, f := range []string{StateFileChildPID} {
74+
p := filepath.Join(opt.StateDir, f)
75+
if err := os.RemoveAll(p); err != nil {
76+
return errors.Wrapf(err, "failed to remove %s", p)
77+
}
78+
}
7179

7280
pipeR, pipeW, err := os.Pipe()
7381
if err != nil {

0 commit comments

Comments
 (0)