Merge pull request #3293 from crosbymichael/atomic-delete

Improve atomic delete
This commit is contained in:
Derek McGowan 2019-05-21 13:54:47 -07:00 committed by GitHub
commit 30082abed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 0 deletions

View File

@ -179,6 +179,9 @@ func atomicDelete(path string) error {
// create a hidden dir for an atomic removal // create a hidden dir for an atomic removal
atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path))) atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path)))
if err := os.Rename(path, atomicPath); err != nil { if err := os.Rename(path, atomicPath); err != nil {
if os.IsNotExist(err) {
return nil
}
return err return err
} }
return os.RemoveAll(atomicPath) return os.RemoveAll(atomicPath)

View File

@ -330,6 +330,10 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
continue continue
} }
id := path.Name() id := path.Name()
// skip hidden directories
if len(id) > 0 && id[0] == '.' {
continue
}
bundle := loadBundle( bundle := loadBundle(
id, id,
filepath.Join(r.state, ns, id), filepath.Join(r.state, ns, id),

View File

@ -134,6 +134,9 @@ func atomicDelete(path string) error {
// create a hidden dir for an atomic removal // create a hidden dir for an atomic removal
atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path))) atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path)))
if err := os.Rename(path, atomicPath); err != nil { if err := os.Rename(path, atomicPath); err != nil {
if os.IsNotExist(err) {
return nil
}
return err return err
} }
return os.RemoveAll(atomicPath) return os.RemoveAll(atomicPath)

View File

@ -214,6 +214,10 @@ func (m *TaskManager) loadTasks(ctx context.Context) error {
continue continue
} }
id := sd.Name() id := sd.Name()
// skip hidden directories
if len(id) > 0 && id[0] == '.' {
continue
}
bundle, err := LoadBundle(ctx, m.state, id) bundle, err := LoadBundle(ctx, m.state, id)
if err != nil { if err != nil {
// fine to return error here, it is a programmer error if the context // fine to return error here, it is a programmer error if the context