From 5bcd2f6860fb4247c844e6e9338a4fef7e07f9f7 Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Mon, 12 Feb 2024 13:31:44 -0500 Subject: [PATCH] builder/dockerfile: ADD with best-effort xattrs Archives being unpacked by Dockerfiles may have been created on other OSes with different conventions and semantics for xattrs, making them impossible to apply when extracting. Restore the old best-effort xattr behaviour users have come to depend on in the classic builder. The (archive.Archiver).UntarPath function does not allow the options passed to Untar to be customized. It also happens to be a trivial wrapper around the Untar function. Inline the function body and add the option. Signed-off-by: Cory Snider --- builder/dockerfile/copy.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/builder/dockerfile/copy.go b/builder/dockerfile/copy.go index 62fbfb656d260..7342a8961acac 100644 --- a/builder/dockerfile/copy.go +++ b/builder/dockerfile/copy.go @@ -459,7 +459,16 @@ func performCopyForInfo(dest copyInfo, source copyInfo, options copyFileOptions) return copyDirectory(archiver, srcPath, destPath, options.identity) } if options.decompress && archive.IsArchivePath(srcPath) && !source.noDecompress { - return archiver.UntarPath(srcPath, destPath) + f, err := os.Open(srcPath) + if err != nil { + return err + } + defer f.Close() + options := &archive.TarOptions{ + IDMap: archiver.IDMapping, + BestEffortXattrs: true, + } + return archiver.Untar(f, destPath, options) } destExistsAsDir, err := isExistingDirectory(destPath)