From 4e8b2f309a3576f82e7cae1656a34b4a30721de9 Mon Sep 17 00:00:00 2001 From: Iceber Gu Date: Mon, 15 Mar 2021 12:47:33 +0800 Subject: [PATCH] rootfs: fix the error handling of the createInitLayer Signed-off-by: Iceber Gu --- rootfs/init.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rootfs/init.go b/rootfs/init.go index 325e5531d..9316b9dda 100644 --- a/rootfs/init.go +++ b/rootfs/init.go @@ -67,7 +67,7 @@ func InitRootFS(ctx context.Context, name string, parent digest.Digest, readonly return snapshotter.Prepare(ctx, name, parentS) } -func createInitLayer(ctx context.Context, parent, initName string, initFn func(string) error, snapshotter snapshots.Snapshotter, mounter Mounter) (string, error) { +func createInitLayer(ctx context.Context, parent, initName string, initFn func(string) error, snapshotter snapshots.Snapshotter, mounter Mounter) (_ string, retErr error) { initS := fmt.Sprintf("%s %s", parent, initName) if _, err := snapshotter.Stat(ctx, initS); err == nil { return initS, nil @@ -87,7 +87,7 @@ func createInitLayer(ctx context.Context, parent, initName string, initFn func(s } defer func() { - if err != nil { + if retErr != nil { if rerr := snapshotter.Remove(ctx, td); rerr != nil { log.G(ctx).Errorf("Failed to remove snapshot %s: %v", td, rerr) }