mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
add err handling, close fd
Signed-off-by: allencloud <allen.sun@daocloud.io>
(cherry picked from commit 2281ce7e98
)
This commit is contained in:
parent
63ce6b60d5
commit
db9b930abc
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.
|
// Push pushes a plugin to the store.
|
||||||
func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.AuthConfig) error {
|
func (pm *Manager) Push(name string, metaHeader http.Header, authConfig *types.AuthConfig) error {
|
||||||
p, err := pm.get(name)
|
p, err := pm.get(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
dest := filepath.Join(pm.libRoot, p.P.ID)
|
dest := filepath.Join(pm.libRoot, p.P.ID)
|
||||||
config, err := os.Open(filepath.Join(dest, "manifest.json"))
|
config, err := os.Open(filepath.Join(dest, "manifest.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer config.Close()
|
||||||
|
|
||||||
rootfs, err := archive.Tar(filepath.Join(dest, "rootfs"), archive.Gzip)
|
rootfs, err := archive.Tar(filepath.Join(dest, "rootfs"), archive.Gzip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -191,6 +191,7 @@ func WritePullData(pd PullData, dest string, extract bool) error {
|
||||||
if !extract {
|
if !extract {
|
||||||
f, err := os.Create(filepath.Join(dest, fmt.Sprintf("layer%d.tar", i)))
|
f, err := os.Create(filepath.Join(dest, fmt.Sprintf("layer%d.tar", i)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
l.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
io.Copy(f, l)
|
io.Copy(f, l)
|
||||||
|
|
|
@ -74,6 +74,7 @@ func Push(name string, rs registry.Service, metaHeader http.Header, authConfig *
|
||||||
r := io.TeeReader(f, h)
|
r := io.TeeReader(f, h)
|
||||||
_, err = io.Copy(bw, r)
|
_, err = io.Copy(bw, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
f.Close()
|
||||||
logrus.Debugf("Error in io.Copy: %v", err)
|
logrus.Debugf("Error in io.Copy: %v", err)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,12 +155,18 @@ func Handle(capability string, callback func(string, *plugins.Client)) {
|
||||||
|
|
||||||
func (pm *Manager) get(name string) (*plugin, error) {
|
func (pm *Manager) get(name string) (*plugin, error) {
|
||||||
pm.RLock()
|
pm.RLock()
|
||||||
|
defer pm.RUnlock()
|
||||||
|
|
||||||
id, nameOk := pm.nameToID[name]
|
id, nameOk := pm.nameToID[name]
|
||||||
p, idOk := pm.plugins[id]
|
if !nameOk {
|
||||||
pm.RUnlock()
|
|
||||||
if !nameOk || !idOk {
|
|
||||||
return nil, ErrNotFound(name)
|
return nil, ErrNotFound(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p, idOk := pm.plugins[id]
|
||||||
|
if !idOk {
|
||||||
|
return nil, ErrNotFound(name)
|
||||||
|
}
|
||||||
|
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue