1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix #34953 how volumes are pruned from daemon

- Call the function that create an event entry while volumes are
pruning.
- Pass volume.Volume type on volumeRm instead of a name. Volume lookup is done
on the exported VolumeRm function.
- Skip volume deletion when force option used and it does not exists.

Signed-off-by: Nicolas Sterchele <sterchele.nicolas@gmail.com>
This commit is contained in:
Nicolas Sterchele 2017-09-24 18:19:59 +02:00
parent c982ee805d
commit 63864ad8c1
2 changed files with 13 additions and 8 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/container"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/volume"
volumestore "github.com/docker/docker/volume/store"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@ -148,10 +149,19 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo
// If the volume is referenced by a container it is not removed
// This is called directly from the Engine API
func (daemon *Daemon) VolumeRm(name string, force bool) error {
err := daemon.volumeRm(name)
v, err := daemon.volumes.Get(name)
if err != nil {
if force && volumestore.IsNotExist(err) {
return nil
}
return err
}
err = daemon.volumeRm(v)
if err != nil && volumestore.IsInUse(err) {
return stateConflictError{err}
}
if err == nil || force {
daemon.volumes.Purge(name)
return nil
@ -159,12 +169,7 @@ func (daemon *Daemon) VolumeRm(name string, force bool) error {
return err
}
func (daemon *Daemon) volumeRm(name string) error {
v, err := daemon.volumes.Get(name)
if err != nil {
return err
}
func (daemon *Daemon) volumeRm(v volume.Volume) error {
if err := daemon.volumes.Remove(v); err != nil {
return errors.Wrap(err, "unable to remove volume")
}

View file

@ -140,7 +140,7 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg
if err != nil {
logrus.Warnf("could not determine size of volume %s: %v", name, err)
}
err = daemon.volumes.Remove(v)
err = daemon.volumeRm(v)
if err != nil {
logrus.Warnf("could not remove volume %s: %v", name, err)
return nil