Add -o flag to tar decompressor (#17427)

For normal users, `-o` or `--no-same-owner` (GNU extension) is
the default behavior, but for the root user, `tar` attempts to preserve
the ownership from the tarball.

This makes `tar` use `-o` all the time.  This should improve untarring
files owned by users not available in rootless Docker builds.
This commit is contained in:
Harmen Stoppels 2020-07-14 00:19:04 +02:00 committed by GitHub
parent 3e13137f6e
commit 2b809a5374
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,7 +14,7 @@
NOTAR_EXTS = ["zip", "tgz", "tbz2", "txz"] NOTAR_EXTS = ["zip", "tgz", "tbz2", "txz"]
# Add PRE_EXTS and EXTS last so that .tar.gz is matched *before* .tar or .gz # Add PRE_EXTS and EXTS last so that .tar.gz is matched *before* .tar or .gz
ALLOWED_ARCHIVE_TYPES = [".".join(l) for l in product( ALLOWED_ARCHIVE_TYPES = [".".join(ext) for ext in product(
PRE_EXTS, EXTS)] + PRE_EXTS + EXTS + NOTAR_EXTS PRE_EXTS, EXTS)] + PRE_EXTS + EXTS + NOTAR_EXTS
@ -36,7 +36,7 @@ def decompressor_for(path, extension=None):
bunzip2 = which('bunzip2', required=True) bunzip2 = which('bunzip2', required=True)
return bunzip2 return bunzip2
tar = which('tar', required=True) tar = which('tar', required=True)
tar.add_default_arg('-xf') tar.add_default_arg('-oxf')
return tar return tar