Skip to content

Commit

Permalink
Add helper to retrieve origin
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sjoerdsimons committed Apr 27, 2022
1 parent fea1b49 commit 07af4c4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion actions/overlay_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion actions/raw_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion actions/unpack_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 07af4c4

Please sign in to comment.