1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

graph: clarify the need for named error

Signed-off-by: Vincent Batts <vbatts@redhat.com>
This commit is contained in:
Vincent Batts 2015-07-17 10:01:52 -04:00
parent ac3f7c71b8
commit a40e337882

View file

@ -177,6 +177,7 @@ func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, contain
// Register imports a pre-existing image into the graph. // Register imports a pre-existing image into the graph.
func (graph *Graph) Register(img *Image, layerData archive.ArchiveReader) (err error) { func (graph *Graph) Register(img *Image, layerData archive.ArchiveReader) (err error) {
if err := image.ValidateID(img.ID); err != nil { if err := image.ValidateID(img.ID); err != nil {
return err return err
} }
@ -186,10 +187,11 @@ func (graph *Graph) Register(img *Image, layerData archive.ArchiveReader) (err e
graph.imageMutex.Lock(img.ID) graph.imageMutex.Lock(img.ID)
defer graph.imageMutex.Unlock(img.ID) defer graph.imageMutex.Unlock(img.ID)
// The returned `error` must be named in this function's signature so that
// `err` is not shadowed in this deferred cleanup.
defer func() { defer func() {
// If any error occurs, remove the new dir from the driver. // If any error occurs, remove the new dir from the driver.
// Don't check for errors since the dir might not have been created. // Don't check for errors since the dir might not have been created.
// FIXME: this leaves a possible race condition.
if err != nil { if err != nil {
graph.driver.Remove(img.ID) graph.driver.Remove(img.ID)
} }