Browse code

plugin: fix naked returns, output vars

plugin/backend_linux.go:722:3: naked return in func `CreateFromContext` with 112 lines of code (nakedret)
return
^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/02/19 05:23:15
Showing 1 changed files
... ...
@@ -620,7 +620,7 @@ func (pm *Manager) Set(name string, args []string) error {
620 620
 
621 621
 // CreateFromContext creates a plugin from the given pluginDir which contains
622 622
 // both the rootfs and the config.json and a repoName with optional tag.
623
-func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) (err error) {
623
+func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) (retErr error) {
624 624
 	pm.muGC.RLock()
625 625
 	defer pm.muGC.RUnlock()
626 626
 
... ...
@@ -641,7 +641,11 @@ func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser,
641 641
 	if err != nil {
642 642
 		return errors.Wrap(err, "failed to create temp directory")
643 643
 	}
644
-	defer os.RemoveAll(tmpRootFSDir)
644
+	defer func() {
645
+		if err := os.RemoveAll(tmpRootFSDir); err != nil {
646
+			log.G(ctx).WithError(err).Warn("failed to remove temp rootfs directory")
647
+		}
648
+	}()
645 649
 
646 650
 	var configJSON []byte
647 651
 	rootFS := splitConfigRootFSFromTar(tarCtx, &configJSON)
... ...
@@ -686,7 +690,7 @@ func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser,
686 686
 		return err
687 687
 	}
688 688
 	defer func() {
689
-		if err != nil {
689
+		if retErr != nil {
690 690
 			go pm.GC()
691 691
 		}
692 692
 	}()
... ...
@@ -713,13 +717,13 @@ func (pm *Manager) CreateFromContext(ctx context.Context, tarCtx io.ReadCloser,
713 713
 	configDigest := configBlob.Digest()
714 714
 	layers := []digest.Digest{rootFSBlob.Digest()}
715 715
 
716
-	manifest, err := buildManifest(ctx, pm.blobStore, configDigest, layers)
716
+	mfst, err := buildManifest(ctx, pm.blobStore, configDigest, layers)
717 717
 	if err != nil {
718 718
 		return err
719 719
 	}
720
-	desc, err := writeManifest(ctx, pm.blobStore, &manifest)
720
+	desc, err := writeManifest(ctx, pm.blobStore, &mfst)
721 721
 	if err != nil {
722
-		return
722
+		return err
723 723
 	}
724 724
 
725 725
 	p, err := pm.createPlugin(name, configDigest, desc.Digest, layers, tmpRootFSDir, nil)