From a634fc119d3d0df71fd802b34cda7ab2237f191d Mon Sep 17 00:00:00 2001 From: George Boukeas Date: Thu, 3 Oct 2024 16:01:36 +0100 Subject: [PATCH] [CERTTF-413] fix: include `chmod` method in the tarfile patch (#368) This allows for directories to be extracted. The filtered `mode` for directories is `None` and the unpatched `chmod` is not forgiving of that. --- agent/testflinger_agent/tarfile_patch.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/agent/testflinger_agent/tarfile_patch.py b/agent/testflinger_agent/tarfile_patch.py index 1cc3ad42..2abbad1d 100644 --- a/agent/testflinger_agent/tarfile_patch.py +++ b/agent/testflinger_agent/tarfile_patch.py @@ -258,6 +258,15 @@ def extractall( except ExtractError as e: self._handle_nonfatal_error(e) + def chmod(self, tarinfo, targetpath): + """Set file permissions of targetpath according to tarinfo.""" + if tarinfo.mode is None: + return + try: + os.chmod(targetpath, tarinfo.mode) + except OSError: + raise ExtractError("could not change mode") + # make sure `open` is available when this module is imported and it # returns a `TarFilePatched` object instead of a `TarFile` one