From 2805a4374f08e1e69f03156ff5344f01d947f739 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Fri, 21 Sep 2018 15:58:20 -0400 Subject: [PATCH] layerStore.Put(): always check for Create() errors If we needed to try to update the ID mappings on a just-created layer, we were inadvertently failing to check that the layer had been successfully created. Signed-off-by: Nalin Dahyabhai --- layers.go | 17 +++++++++++++---- layers_ffjson.go | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/layers.go b/layers.go index 9989bd6be3..fe263ba632 100644 --- a/layers.go +++ b/layers.go @@ -558,13 +558,22 @@ func (r *layerStore) Put(id string, parentLayer *Layer, names []string, mountLab StorageOpt: options, } if writeable { - err = r.driver.CreateReadWrite(id, parent, &opts) + if err = r.driver.CreateReadWrite(id, parent, &opts); err != nil { + if id != "" { + return nil, -1, errors.Wrapf(err, "error creating read-write layer with ID %q", id) + } + return nil, -1, errors.Wrapf(err, "error creating read-write layer") + } } else { - err = r.driver.Create(id, parent, &opts) + if err = r.driver.Create(id, parent, &opts); err != nil { + if id != "" { + return nil, -1, errors.Wrapf(err, "error creating layer with ID %q", id) + } + return nil, -1, errors.Wrapf(err, "error creating layer") + } } if !reflect.DeepEqual(parentMappings.UIDs(), idMappings.UIDs()) || !reflect.DeepEqual(parentMappings.GIDs(), idMappings.GIDs()) { - err = r.driver.UpdateLayerIDMap(id, parentMappings, idMappings, mountLabel) - if err != nil { + if err = r.driver.UpdateLayerIDMap(id, parentMappings, idMappings, mountLabel); err != nil { // We don't have a record of this layer, but at least // try to clean it up underneath us. r.driver.Remove(id) diff --git a/layers_ffjson.go b/layers_ffjson.go index 125b5d8c97..09b5d0f33e 100644 --- a/layers_ffjson.go +++ b/layers_ffjson.go @@ -1,5 +1,5 @@ // Code generated by ffjson . DO NOT EDIT. -// source: layers.go +// source: ./layers.go package storage