add err handling, close fd
Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
parent
cccfe63e86
commit
2281ce7e98
4 changed files with 16 additions and 3 deletions
|
@ -101,11 +101,16 @@ func (pm *Manager) List() ([]types.Plugin, error) {
|
|||
// Push pushes a plugin to the store.
|
||||
func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.AuthConfig) error {
|
||||
p, err := pm.get(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dest := filepath.Join(pm.libRoot, p.P.ID)
|
||||
config, err := os.Open(filepath.Join(dest, "manifest.json"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer config.Close()
|
||||
|
||||
rootfs, err := archive.Tar(filepath.Join(dest, "rootfs"), archive.Gzip)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -191,6 +191,7 @@ func WritePullData(pd PullData, dest string, extract bool) error {
|
|||
if !extract {
|
||||
f, err := os.Create(filepath.Join(dest, fmt.Sprintf("layer%d.tar", i)))
|
||||
if err != nil {
|
||||
l.Close()
|
||||
return err
|
||||
}
|
||||
io.Copy(f, l)
|
||||
|
|
|
@ -74,6 +74,7 @@ func Push(name string, rs registry.Service, metaHeader http.Header, authConfig *
|
|||
r := io.TeeReader(f, h)
|
||||
_, err = io.Copy(bw, r)
|
||||
if err != nil {
|
||||
f.Close()
|
||||
logrus.Debugf("Error in io.Copy: %v", err)
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -155,12 +155,18 @@ func Handle(capability string, callback func(string, *plugins.Client)) {
|
|||
|
||||
func (pm *Manager) get(name string) (*plugin, error) {
|
||||
pm.RLock()
|
||||
defer pm.RUnlock()
|
||||
|
||||
id, nameOk := pm.nameToID[name]
|
||||
p, idOk := pm.plugins[id]
|
||||
pm.RUnlock()
|
||||
if !nameOk || !idOk {
|
||||
if !nameOk {
|
||||
return nil, ErrNotFound(name)
|
||||
}
|
||||
|
||||
p, idOk := pm.plugins[id]
|
||||
if !idOk {
|
||||
return nil, ErrNotFound(name)
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue