mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
[plugins] return err when failing remove
Fixes a case where removing the plugin from disk would
fail silently. Also moves pluginStore remove after we
remove from disk, so 'docker plugin ls' doesn't isn't
empty in case it errors out.
Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
(cherry picked from commit fb11164c4f
)
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
a80251e8cd
commit
a260417927
1 changed files with 12 additions and 6 deletions
|
@ -5,7 +5,6 @@ package plugin
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -23,6 +22,7 @@ import (
|
||||||
"github.com/docker/docker/plugin/distribution"
|
"github.com/docker/docker/plugin/distribution"
|
||||||
"github.com/docker/docker/plugin/v2"
|
"github.com/docker/docker/plugin/v2"
|
||||||
"github.com/docker/docker/reference"
|
"github.com/docker/docker/reference"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.A
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove deletes plugin's root directory.
|
// Remove deletes plugin's root directory.
|
||||||
func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
|
func (pm *Manager) Remove(name string, config *types.PluginRmConfig) (err error) {
|
||||||
p, err := pm.pluginStore.GetByName(name)
|
p, err := pm.pluginStore.GetByName(name)
|
||||||
pm.mu.RLock()
|
pm.mu.RLock()
|
||||||
c := pm.cMap[p]
|
c := pm.cMap[p]
|
||||||
|
@ -294,12 +294,18 @@ func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
id := p.GetID()
|
id := p.GetID()
|
||||||
pm.pluginStore.Remove(p)
|
|
||||||
pluginDir := filepath.Join(pm.libRoot, id)
|
pluginDir := filepath.Join(pm.libRoot, id)
|
||||||
if err := os.RemoveAll(pluginDir); err != nil {
|
|
||||||
logrus.Warnf("unable to remove %q from plugin remove: %v", pluginDir, err)
|
defer func() {
|
||||||
|
if err == nil || config.ForceRemove {
|
||||||
|
pm.pluginStore.Remove(p)
|
||||||
|
pm.pluginEventLogger(id, name, "remove")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err = os.RemoveAll(pluginDir); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to remove plugin directory")
|
||||||
}
|
}
|
||||||
pm.pluginEventLogger(id, name, "remove")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue