From 5b7a327c4776201574e62b653ef794e9010bb7ee Mon Sep 17 00:00:00 2001 From: Ace-Tang Date: Fri, 19 Apr 2019 16:49:03 +0800 Subject: [PATCH] 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 Signed-off-by: Michael Crosby --- runtime/v1/linux/bundle.go | 3 +++ runtime/v1/linux/runtime.go | 4 ++++ runtime/v2/bundle.go | 3 +++ runtime/v2/manager.go | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/runtime/v1/linux/bundle.go b/runtime/v1/linux/bundle.go index ae0e73f28..5be20f735 100644 --- a/runtime/v1/linux/bundle.go +++ b/runtime/v1/linux/bundle.go @@ -179,6 +179,9 @@ func atomicDelete(path string) error { // create a hidden dir for an atomic removal atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path))) if err := os.Rename(path, atomicPath); err != nil { + if os.IsNotExist(err) { + return nil + } return err } return os.RemoveAll(atomicPath) diff --git a/runtime/v1/linux/runtime.go b/runtime/v1/linux/runtime.go index ceb30f178..86a94e5c5 100644 --- a/runtime/v1/linux/runtime.go +++ b/runtime/v1/linux/runtime.go @@ -330,6 +330,10 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) { continue } id := path.Name() + // skip hidden directories + if len(id) > 0 && id[0] == '.' { + continue + } bundle := loadBundle( id, filepath.Join(r.state, ns, id), diff --git a/runtime/v2/bundle.go b/runtime/v2/bundle.go index 7897a1c64..8c1673875 100644 --- a/runtime/v2/bundle.go +++ b/runtime/v2/bundle.go @@ -134,6 +134,9 @@ func atomicDelete(path string) error { // create a hidden dir for an atomic removal atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path))) if err := os.Rename(path, atomicPath); err != nil { + if os.IsNotExist(err) { + return nil + } return err } return os.RemoveAll(atomicPath) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 19daefdba..a0ff08487 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -214,6 +214,10 @@ func (m *TaskManager) loadTasks(ctx context.Context) error { continue } id := sd.Name() + // skip hidden directories + if len(id) > 0 && id[0] == '.' { + continue + } bundle, err := LoadBundle(ctx, m.state, id) if err != nil { // fine to return error here, it is a programmer error if the context