Fix #34953 how volumes are pruned from daemon
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/container" |
| 12 | 12 |
"github.com/docker/docker/layer" |
| 13 | 13 |
"github.com/docker/docker/pkg/system" |
| 14 |
+ "github.com/docker/docker/volume" |
|
| 14 | 15 |
volumestore "github.com/docker/docker/volume/store" |
| 15 | 16 |
"github.com/pkg/errors" |
| 16 | 17 |
"github.com/sirupsen/logrus" |
| ... | ... |
@@ -148,10 +149,19 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo |
| 148 | 148 |
// If the volume is referenced by a container it is not removed |
| 149 | 149 |
// This is called directly from the Engine API |
| 150 | 150 |
func (daemon *Daemon) VolumeRm(name string, force bool) error {
|
| 151 |
- err := daemon.volumeRm(name) |
|
| 151 |
+ v, err := daemon.volumes.Get(name) |
|
| 152 |
+ if err != nil {
|
|
| 153 |
+ if force && volumestore.IsNotExist(err) {
|
|
| 154 |
+ return nil |
|
| 155 |
+ } |
|
| 156 |
+ return err |
|
| 157 |
+ } |
|
| 158 |
+ |
|
| 159 |
+ err = daemon.volumeRm(v) |
|
| 152 | 160 |
if err != nil && volumestore.IsInUse(err) {
|
| 153 | 161 |
return stateConflictError{err}
|
| 154 | 162 |
} |
| 163 |
+ |
|
| 155 | 164 |
if err == nil || force {
|
| 156 | 165 |
daemon.volumes.Purge(name) |
| 157 | 166 |
return nil |
| ... | ... |
@@ -159,12 +169,7 @@ func (daemon *Daemon) VolumeRm(name string, force bool) error {
|
| 159 | 159 |
return err |
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 |
-func (daemon *Daemon) volumeRm(name string) error {
|
|
| 163 |
- v, err := daemon.volumes.Get(name) |
|
| 164 |
- if err != nil {
|
|
| 165 |
- return err |
|
| 166 |
- } |
|
| 167 |
- |
|
| 162 |
+func (daemon *Daemon) volumeRm(v volume.Volume) error {
|
|
| 168 | 163 |
if err := daemon.volumes.Remove(v); err != nil {
|
| 169 | 164 |
return errors.Wrap(err, "unable to remove volume") |
| 170 | 165 |
} |
| ... | ... |
@@ -140,7 +140,7 @@ func (daemon *Daemon) VolumesPrune(ctx context.Context, pruneFilters filters.Arg |
| 140 | 140 |
if err != nil {
|
| 141 | 141 |
logrus.Warnf("could not determine size of volume %s: %v", name, err)
|
| 142 | 142 |
} |
| 143 |
- err = daemon.volumes.Remove(v) |
|
| 143 |
+ err = daemon.volumeRm(v) |
|
| 144 | 144 |
if err != nil {
|
| 145 | 145 |
logrus.Warnf("could not remove volume %s: %v", name, err)
|
| 146 | 146 |
return nil |