Skip to content

Commit 5b7a327

Browse files
Ace-Tangcrosbymichael
authored andcommitted
Improve atomic delete
skip hidden directories in load task, and return soon if path not exist in atomicDelete carry of #3233 Closes #3233 Signed-off-by: Ace-Tang <[email protected]> Signed-off-by: Michael Crosby <[email protected]>
1 parent cafda1c commit 5b7a327

4 files changed

Lines changed: 14 additions & 0 deletions

File tree

runtime/v1/linux/bundle.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ func atomicDelete(path string) error {
179179
// create a hidden dir for an atomic removal
180180
atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path)))
181181
if err := os.Rename(path, atomicPath); err != nil {
182+
if os.IsNotExist(err) {
183+
return nil
184+
}
182185
return err
183186
}
184187
return os.RemoveAll(atomicPath)

runtime/v1/linux/runtime.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
330330
continue
331331
}
332332
id := path.Name()
333+
// skip hidden directories
334+
if len(id) > 0 && id[0] == '.' {
335+
continue
336+
}
333337
bundle := loadBundle(
334338
id,
335339
filepath.Join(r.state, ns, id),

runtime/v2/bundle.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func atomicDelete(path string) error {
134134
// create a hidden dir for an atomic removal
135135
atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path)))
136136
if err := os.Rename(path, atomicPath); err != nil {
137+
if os.IsNotExist(err) {
138+
return nil
139+
}
137140
return err
138141
}
139142
return os.RemoveAll(atomicPath)

runtime/v2/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func (m *TaskManager) loadTasks(ctx context.Context) error {
214214
continue
215215
}
216216
id := sd.Name()
217+
// skip hidden directories
218+
if len(id) > 0 && id[0] == '.' {
219+
continue
220+
}
217221
bundle, err := LoadBundle(ctx, m.state, id)
218222
if err != nil {
219223
// fine to return error here, it is a programmer error if the context

0 commit comments

Comments
 (0)