From 95b9c4f4a4231e04bf9aafd34c0afd46910295a7 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 29 Feb 2024 11:09:40 -0800 Subject: [PATCH] dockerfile: don't silently ignore --parents if not labs Instead of ignoring the flag and copying wrong files the build should error if labs is not enabled. Signed-off-by: Tonis Tiigi --- frontend/dockerfile/instructions/parse.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/dockerfile/instructions/parse.go b/frontend/dockerfile/instructions/parse.go index 1d41d9f2c224..40246fe5e4c4 100644 --- a/frontend/dockerfile/instructions/parse.go +++ b/frontend/dockerfile/instructions/parse.go @@ -334,17 +334,20 @@ func parseCopy(req parseRequest) (*CopyCommand, error) { } var flExcludes *Flag + var flParents *Flag - // silently ignore if not -labs if excludePatternsEnabled { flExcludes = req.flags.AddStrings("exclude") } + if parentsEnabled { + flParents = req.flags.AddBool("parents", false) + } flChown := req.flags.AddString("chown", "") flFrom := req.flags.AddString("from", "") flChmod := req.flags.AddString("chmod", "") flLink := req.flags.AddBool("link", false) - flParents := req.flags.AddBool("parents", false) + if err := req.flags.Parse(); err != nil { return nil, err } @@ -361,7 +364,7 @@ func parseCopy(req parseRequest) (*CopyCommand, error) { Chown: flChown.Value, Chmod: flChmod.Value, Link: flLink.Value == "true", - Parents: (flParents.Value == "true") && parentsEnabled, // silently ignore if not -labs + Parents: flParents != nil && flParents.Value == "true", ExcludePatterns: stringValuesFromFlagIfPossible(flExcludes), }, nil }