diff --git a/src/data_dir.py b/src/data_dir.py index c0e4825..f29253b 100644 --- a/src/data_dir.py +++ b/src/data_dir.py @@ -70,12 +70,13 @@ class DataDir: shutil.rmtree(target_path) self.logger.debug("Deleted %s", target_path) tar_file.extractall(target_path, filter="data") - for target_file in target_path.iterdir(): - if re.match(r"^\..*", target_file.name): # remove dot files + for target_file in target_path.rglob("*"): + if target_file.name.startswith("."): # remove dot files if target_file.is_dir(): shutil.rmtree(target_file) else: target_file.unlink() + self.logger.debug("Removed %s", target_file) self.logger.debug("Extracted tar to %s", target_path) def remove(self, path: str) -> None: diff --git a/tests/__init__.py b/tests/__init__.py index 30cd4e9..ed71692 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -26,7 +26,7 @@ class BaseTestCase(unittest.TestCase): self.tmp_path = pathlib.Path(self.tmp_dir.name) return self.tmp_dir.name - def mock(self, spec: type | None = None) -> unittest.mock.Mock: + def new_mock(self, spec: type | None = None) -> unittest.mock.Mock: mock = unittest.mock.Mock(spec) self.mocks += [mock] return mock diff --git a/tests/test_data_dir.py b/tests/test_data_dir.py index 8929025..e572f13 100644 --- a/tests/test_data_dir.py +++ b/tests/test_data_dir.py @@ -97,10 +97,21 @@ class TestDataDir(BaseTestCase): def test_extract_tar_bytes_create_without_dotfiles(self) -> None: tar_bytes = self.__get_tar_bytes( - {"value": "value", ".value": "value", ".git/test": "test"} + { + "value": "value", + ".value": "value", + ".git/test": "test", + "dir/.invalid": "value", + "dir/.test/hello": "value", + } ) self.data_dir.extract_tar_bytes("test_1", tar_bytes) self.assert_file_content(self.tmp_path / "test_1" / "value", "value") + assert not (self.tmp_path / "test_1" / ".value").exists() + assert not (self.tmp_path / "test_1" / ".git").exists() + assert (self.tmp_path / "test_1" / "dir").exists() + assert not (self.tmp_path / "test_1" / "dir" / ".invalid").exists() + assert not (self.tmp_path / "test_1" / "dir" / ".test").exists() def test_extract_tar_bytes_update(self) -> None: self.__create_path(