From 07af4c497f16f55ab0a19bcf41a7b687e1c50573 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 26 Apr 2022 22:12:12 +0200 Subject: [PATCH] Add helper to retrieve origin The origins hash table is inside the commonContext structure which is shared by all Contexts. This mostly works correctly as most origins are not specific to the recipe that's executed but to either the run or the progress of a run. Such as "filesystem" or "artifacts". However this is not the case for the "recipe" origin. To resolve that add a helper function which returns the current context RecipeDir and otherwise simply the respective value in the common Origins table. Signed-off-by: Sjoerd Simons --- action.go | 9 +++++++++ actions/overlay_action.go | 2 +- actions/raw_action.go | 2 +- actions/unpack_action.go | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/action.go b/action.go index deaa6dfd..48eb6f96 100644 --- a/action.go +++ b/action.go @@ -45,6 +45,15 @@ type DebosContext struct { Architecture string } +func (c *DebosContext) Origin(o string) (string, bool) { + if o == "recipe" { + return c.RecipeDir, true + } else { + path, found := c.Origins[o]; + return path, found + } +} + type Action interface { /* FIXME verify should probably be prepare or somesuch */ Verify(context *DebosContext) error diff --git a/actions/overlay_action.go b/actions/overlay_action.go index b5e4924d..6a50a4b0 100644 --- a/actions/overlay_action.go +++ b/actions/overlay_action.go @@ -52,7 +52,7 @@ func (overlay *OverlayAction) Run(context *debos.DebosContext) error { //Trying to get a filename from exports first if len(overlay.Origin) > 0 { var found bool - if origin, found = context.Origins[overlay.Origin]; !found { + if origin, found = context.Origin(overlay.Origin); !found { return fmt.Errorf("Origin not found '%s'", overlay.Origin) } } diff --git a/actions/raw_action.go b/actions/raw_action.go index ec756388..013eeae8 100644 --- a/actions/raw_action.go +++ b/actions/raw_action.go @@ -85,7 +85,7 @@ func (raw *RawAction) Verify(context *debos.DebosContext) error { func (raw *RawAction) Run(context *debos.DebosContext) error { raw.LogStart() - origin, found := context.Origins[raw.Origin] + origin, found := context.Origin(raw.Origin) if !found { return fmt.Errorf("Origin `%s` doesn't exist\n", raw.Origin) } diff --git a/actions/unpack_action.go b/actions/unpack_action.go index d4993b14..65551ada 100644 --- a/actions/unpack_action.go +++ b/actions/unpack_action.go @@ -73,7 +73,7 @@ func (pf *UnpackAction) Run(context *debos.DebosContext) error { if len(pf.Origin) > 0 { var found bool //Trying to get a filename from origins first - origin, found = context.Origins[pf.Origin] + origin, found = context.Origin(pf.Origin) if !found { return fmt.Errorf("Origin not found '%s'", pf.Origin) }