diff --git a/linux/bundle.go b/linux/bundle.go index 9204fc74e..66c0cb483 100644 --- a/linux/bundle.go +++ b/linux/bundle.go @@ -14,13 +14,15 @@ import ( client "github.com/containerd/containerd/linux/shim" "github.com/containerd/containerd/runtime" "github.com/containerd/containerd/typeurl" + "github.com/pkg/errors" ) -func loadBundle(path, namespace string, events *events.Exchange) *bundle { +func loadBundle(path, workdir, namespace string, events *events.Exchange) *bundle { return &bundle{ path: path, namespace: namespace, events: events, + workDir: workdir, } } @@ -112,7 +114,16 @@ func (b *bundle) Connect(ctx context.Context, remote bool) (*client.Client, erro // Delete deletes the bundle from disk func (b *bundle) Delete() error { - return os.RemoveAll(b.path) + err := os.RemoveAll(b.path) + if err == nil { + return os.RemoveAll(b.workDir) + } + // error removing the bundle path; still attempt removing work dir + err2 := os.RemoveAll(b.workDir) + if err2 == nil { + return err + } + return errors.Wrapf(err, "Failed to remove both bundle and workdir locations: %v", err2) } func (b *bundle) shimAddress() string { diff --git a/linux/runtime.go b/linux/runtime.go index 7f54ff1d0..43c0b20ed 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -211,7 +211,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er } r.tasks.Delete(ctx, lc) - bundle := loadBundle(filepath.Join(r.state, namespace, lc.id), namespace, r.events) + bundle := loadBundle(filepath.Join(r.state, namespace, lc.id), filepath.Join(r.root, namespace, lc.id), namespace, r.events) if err := bundle.Delete(); err != nil { return nil, err } @@ -262,7 +262,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) { continue } id := path.Name() - bundle := loadBundle(filepath.Join(r.state, ns, id), ns, r.events) + bundle := loadBundle(filepath.Join(r.state, ns, id), filepath.Join(r.root, ns, id), ns, r.events) s, err := bundle.Connect(ctx, r.remote) if err != nil {