From 468d6616bfc7fee1b076f0b7c1b9c8a7ded9ec93 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 18 Jul 2023 14:18:42 +0200 Subject: [PATCH] daemon: configureLocalContentStore: return concrete types The interface is defined on the receiver-side, and returning concrete types makes it more transparent what we're creating. As these namespaced wrappers were not exported, let's inline them, so that it's clear at a glance what it's doing. Signed-off-by: Sebastiaan van Stijn --- daemon/content.go | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/daemon/content.go b/daemon/content.go index a97ad20d7b..9338851da9 100644 --- a/daemon/content.go +++ b/daemon/content.go @@ -16,7 +16,7 @@ import ( "go.etcd.io/bbolt" ) -func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leases.Manager, error) { +func (daemon *Daemon) configureLocalContentStore(ns string) (*namespacedContent, *namespacedLeases, error) { if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0o700); err != nil { return nil, nil, errors.Wrap(err, "error creating dir for content store") } @@ -30,7 +30,15 @@ func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leas } md := metadata.NewDB(db, cs, nil) daemon.mdDB = db - return namespacedContentProvider(md.ContentStore(), ns), namespacedLeaseManager(metadata.NewLeaseManager(md), ns), nil + cp := &namespacedContent{ + ns: ns, + provider: md.ContentStore(), + } + lm := &namespacedLeases{ + ns: ns, + manager: metadata.NewLeaseManager(md), + } + return cp, lm, nil } // withDefaultNamespace sets the given namespace on the context if the current @@ -105,14 +113,6 @@ func (cp namespacedContent) ReaderAt(ctx context.Context, desc ocispec.Descripto return cp.provider.ReaderAt(withDefaultNamespace(ctx, cp.ns), desc) } -// namespacedContentProvider sets the namespace if missing before calling the inner provider -func namespacedContentProvider(provider content.Store, ns string) content.Store { - return namespacedContent{ - ns, - provider, - } -} - type namespacedLeases struct { ns string manager leases.Manager @@ -147,11 +147,3 @@ func (nl namespacedLeases) List(ctx context.Context, filter ...string) ([]leases func (nl namespacedLeases) ListResources(ctx context.Context, lease leases.Lease) ([]leases.Resource, error) { return nl.manager.ListResources(withDefaultNamespace(ctx, nl.ns), lease) } - -// namespacedLeaseManager sets the namespace if missing before calling the inner manager -func namespacedLeaseManager(manager leases.Manager, ns string) leases.Manager { - return namespacedLeases{ - ns, - manager, - } -}