Signed-off-by: allencloud <allen.sun@daocloud.io>
(cherry picked from commit 2281ce7e98ec983514450c33c0ef1d90262c3b4f)
| ... | ... |
@@ -101,11 +101,16 @@ func (pm *Manager) List() ([]types.Plugin, error) {
|
| 101 | 101 |
// Push pushes a plugin to the store. |
| 102 | 102 |
func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.AuthConfig) error {
|
| 103 | 103 |
p, err := pm.get(name) |
| 104 |
+ if err != nil {
|
|
| 105 |
+ return err |
|
| 106 |
+ } |
|
| 104 | 107 |
dest := filepath.Join(pm.libRoot, p.P.ID) |
| 105 | 108 |
config, err := os.Open(filepath.Join(dest, "manifest.json")) |
| 106 | 109 |
if err != nil {
|
| 107 | 110 |
return err |
| 108 | 111 |
} |
| 112 |
+ defer config.Close() |
|
| 113 |
+ |
|
| 109 | 114 |
rootfs, err := archive.Tar(filepath.Join(dest, "rootfs"), archive.Gzip) |
| 110 | 115 |
if err != nil {
|
| 111 | 116 |
return err |
| ... | ... |
@@ -155,12 +155,18 @@ func Handle(capability string, callback func(string, *plugins.Client)) {
|
| 155 | 155 |
|
| 156 | 156 |
func (pm *Manager) get(name string) (*plugin, error) {
|
| 157 | 157 |
pm.RLock() |
| 158 |
+ defer pm.RUnlock() |
|
| 159 |
+ |
|
| 158 | 160 |
id, nameOk := pm.nameToID[name] |
| 161 |
+ if !nameOk {
|
|
| 162 |
+ return nil, ErrNotFound(name) |
|
| 163 |
+ } |
|
| 164 |
+ |
|
| 159 | 165 |
p, idOk := pm.plugins[id] |
| 160 |
- pm.RUnlock() |
|
| 161 |
- if !nameOk || !idOk {
|
|
| 166 |
+ if !idOk {
|
|
| 162 | 167 |
return nil, ErrNotFound(name) |
| 163 | 168 |
} |
| 169 |
+ |
|
| 164 | 170 |
return p, nil |
| 165 | 171 |
} |
| 166 | 172 |
|