[plugins] return err when failing remove
| ... | ... |
@@ -5,7 +5,6 @@ package plugin |
| 5 | 5 |
import ( |
| 6 | 6 |
"bytes" |
| 7 | 7 |
"encoding/json" |
| 8 |
- "errors" |
|
| 9 | 8 |
"fmt" |
| 10 | 9 |
"io" |
| 11 | 10 |
"io/ioutil" |
| ... | ... |
@@ -23,6 +22,7 @@ import ( |
| 23 | 23 |
"github.com/docker/docker/plugin/distribution" |
| 24 | 24 |
"github.com/docker/docker/plugin/v2" |
| 25 | 25 |
"github.com/docker/docker/reference" |
| 26 |
+ "github.com/pkg/errors" |
|
| 26 | 27 |
"golang.org/x/net/context" |
| 27 | 28 |
) |
| 28 | 29 |
|
| ... | ... |
@@ -268,7 +268,7 @@ func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.A |
| 268 | 268 |
} |
| 269 | 269 |
|
| 270 | 270 |
// Remove deletes plugin's root directory. |
| 271 |
-func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
|
|
| 271 |
+func (pm *Manager) Remove(name string, config *types.PluginRmConfig) (err error) {
|
|
| 272 | 272 |
p, err := pm.pluginStore.GetByName(name) |
| 273 | 273 |
pm.mu.RLock() |
| 274 | 274 |
c := pm.cMap[p] |
| ... | ... |
@@ -294,12 +294,18 @@ func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
|
| 294 | 294 |
} |
| 295 | 295 |
|
| 296 | 296 |
id := p.GetID() |
| 297 |
- pm.pluginStore.Remove(p) |
|
| 298 | 297 |
pluginDir := filepath.Join(pm.libRoot, id) |
| 299 |
- if err := os.RemoveAll(pluginDir); err != nil {
|
|
| 300 |
- logrus.Warnf("unable to remove %q from plugin remove: %v", pluginDir, err)
|
|
| 298 |
+ |
|
| 299 |
+ defer func() {
|
|
| 300 |
+ if err == nil || config.ForceRemove {
|
|
| 301 |
+ pm.pluginStore.Remove(p) |
|
| 302 |
+ pm.pluginEventLogger(id, name, "remove") |
|
| 303 |
+ } |
|
| 304 |
+ }() |
|
| 305 |
+ |
|
| 306 |
+ if err = os.RemoveAll(pluginDir); err != nil {
|
|
| 307 |
+ return errors.Wrap(err, "failed to remove plugin directory") |
|
| 301 | 308 |
} |
| 302 |
- pm.pluginEventLogger(id, name, "remove") |
|
| 303 | 309 |
return nil |
| 304 | 310 |
} |
| 305 | 311 |
|