From eaf46ca95f05e333abab4242ac99506e5ffd3ba0 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Wed, 12 Jan 2022 15:42:08 +0000 Subject: [PATCH 1/3] actions: overlay: Check source exists during RecipeDir during verification If an overlay (with a source from the recipe directory which is unlikely to change during execution) doesn't exist, the recipe errors out during execution. Let's check early if the overlay exists on the host filesystem inside the recipe directory. Signed-off-by: Christopher Obbard --- actions/overlay_action.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/actions/overlay_action.go b/actions/overlay_action.go index 2b597ce2..1d930405 100644 --- a/actions/overlay_action.go +++ b/actions/overlay_action.go @@ -27,6 +27,7 @@ package actions import ( "fmt" "log" + "os" "path" "github.com/go-debos/debos" @@ -43,6 +44,15 @@ func (overlay *OverlayAction) Verify(context *debos.DebosContext) error { if _, err := debos.RestrictedPath(context.Rootdir, overlay.Destination); err != nil { return err } + + /* only check default origin recipedir */ + if len(overlay.Origin) == 0 { + sourceDir := path.Join(context.RecipeDir, overlay.Source) + if _, err := os.Stat(sourceDir); err != nil { + return err + } + } + return nil } From 32c0b86f53f0956672f9f8dfd75350a783fe7f61 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Thu, 27 Jul 2023 16:54:05 +0100 Subject: [PATCH 2/3] tests: overlay: Add test to overlay missing file Signed-off-by: Christopher Obbard --- .../overlay-non-existent-destination.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml b/tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml index 473a42da..67f1ceec 100644 --- a/tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml +++ b/tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml @@ -1,6 +1,12 @@ architecture: amd64 actions: + # This overlay action is expected to error out here because the source + # doesn't exist in the recipe directory. + - action: overlay + description: Overlay non-existent file + source: non-existent-file + # This overlay action is expected to error out here because the destination # doesn't exist in the filesystem. - action: overlay From add9a02ac61cb08a4e6e63f3ec1a08c1c17dd0c4 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Thu, 27 Jul 2023 16:56:21 +0100 Subject: [PATCH 3/3] =?UTF-8?q?tests:=20Rename=20overlay-non-existent-dest?= =?UTF-8?q?ination=E2=86=92overlay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the overlay-non-existent-destination test now also checks for a non-existent source, let's rename the test to be overlay to better describe the test contents. Signed-off-by: Christopher Obbard --- .../overlay-non-existent-destination.yaml | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml diff --git a/tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml b/tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml deleted file mode 100644 index 67f1ceec..00000000 --- a/tests/overlay-non-existent-destination/overlay-non-existent-destination.yaml +++ /dev/null @@ -1,23 +0,0 @@ -architecture: amd64 - -actions: - # This overlay action is expected to error out here because the source - # doesn't exist in the recipe directory. - - action: overlay - description: Overlay non-existent file - source: non-existent-file - - # This overlay action is expected to error out here because the destination - # doesn't exist in the filesystem. - - action: overlay - description: Overlay file into a non-existent destination - source: overlay-non-existent-destination.yaml - destination: /this/path/does/not/exist/overlay-non-existent-destination.yaml - - - action: run - description: Check if path exists - command: "[ -e /this/path/does/not/exist/overlay-non-existent-destination.yaml ] || exit 1" - - - action: run - postprocess: true - command: echo Test