Skip to content

Commit 33d8261

Browse files
committed
fix state dir clean-up
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
1 parent 3625074 commit 33d8261

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)