devmapper: Remove directory when removing devicemapper device

We're currently leaving around lots of empty directories in
/var/lib/docker/devicemapper/mnt/ for removed images and containers.
Fix this by removing the directory when the device is removed.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
Upstream-commit: 2343fe44533f19ebae5e6127f4a2a19d1d8773fa
Component: engine
This commit is contained in:
Alexander Larsson
2014-02-11 09:40:13 +01:00
parent 60784e353c
commit abb4de8546

View File

@ -7,6 +7,7 @@ import (
"github.com/dotcloud/docker/graphdriver"
"github.com/dotcloud/docker/utils"
"io/ioutil"
"os"
"path"
)
@ -94,7 +95,16 @@ func (d *Driver) Remove(id string) error {
return err
}
// This assumes the device has been properly Get/Put:ed and thus is unmounted
return d.DeviceSet.DeleteDevice(id)
if err := d.DeviceSet.DeleteDevice(id); err != nil {
return err
}
mp := path.Join(d.home, "mnt", id)
if err := os.RemoveAll(mp); err != nil && !os.IsNotExist(err) {
return err
}
return nil
}
func (d *Driver) Get(id string) (string, error) {