diff options
author | Helmut Grohne <helmut@subdivi.de> | 2024-05-09 12:09:55 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2024-05-09 12:09:55 +0200 |
commit | c45a83883625ea5226bace08e72f45782e31c29f (patch) | |
tree | 84d21bfba3c134f8cf46dae544ef107e4524f5bb /examples/chroottar.py | |
parent | aea61a6192949d36adff0b369a4fd2c03502441b (diff) | |
download | python-linuxnamespaces-c45a83883625ea5226bace08e72f45782e31c29f.tar.gz |
add linuxnamespaces.tarinfo.XAttrTarFile
This is a mixin subclass for TarFile that enables it to restore and
apply linux extended attributes as PAX headers in the SCHILY.xattr.*
format. As a consequence, this enables us to process tar archives
containing file system capabilities.
Diffstat (limited to 'examples/chroottar.py')
-rwxr-xr-x | examples/chroottar.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/chroottar.py b/examples/chroottar.py index f43add4..30017e5 100755 --- a/examples/chroottar.py +++ b/examples/chroottar.py @@ -20,6 +20,12 @@ import linuxnamespaces import linuxnamespaces.tarutils +class TarFile( + linuxnamespaces.tarutils.ZstdTarFile, linuxnamespaces.tarutils.XAttrTarFile +): + pass + + def main() -> None: parser = argparse.ArgumentParser() parser.add_argument( @@ -49,9 +55,7 @@ def main() -> None: parentsock.close() # Once we drop privileges via setreuid and friends, we may become # unable to open basetar or to chdir to tdir, so do those early. - with linuxnamespaces.tarutils.ZstdTarFile.open( - args.basetar, "r:*" - ) as tarf: + with TarFile.open(args.basetar, "r:*") as tarf: os.chdir(tdir) linuxnamespaces.unshare( linuxnamespaces.CloneFlags.NEWUSER @@ -112,9 +116,7 @@ def main() -> None: if args.save and ret == 0: tmptar = f"{args.basetar}.new" try: - with linuxnamespaces.tarutils.ZstdTarFile.open( - tmptar, "x:" + comptype - ) as tout: + with TarFile.open(tmptar, "x:" + comptype) as tout: tout.add(tdir, ".") os.rename(tmptar, args.basetar) except: |