diff --git a/swh/core/tarball.py b/swh/core/tarball.py --- a/swh/core/tarball.py +++ b/swh/core/tarball.py @@ -81,13 +81,15 @@ Args: tarpath: path to tarball to uncompress - dest: the destination folder where to uncompress the tarball + dest: the destination folder where to uncompress the tarball, + it will be created if it does not exist Raises: ValueError when a problem occurs during unpacking """ try: + os.makedirs(dest, exist_ok=True) shutil.unpack_archive(tarpath, extract_dir=dest) except shutil.ReadError as e: raise ValueError(f"Problem during unpacking {tarpath}. Reason: {e}") diff --git a/swh/core/tests/test_tarball.py b/swh/core/tests/test_tarball.py --- a/swh/core/tests/test_tarball.py +++ b/swh/core/tests/test_tarball.py @@ -127,21 +127,6 @@ tarball.uncompress(tarpath, tmp_path) -def test_uncompress_tar_failure2(tmp_path, datadir): - """Unpack Existent tarball into an inexistent folder should fail - - """ - filename = "groff-1.02.tar.Z" - tarpath = os.path.join(datadir, "archives", filename) - - assert os.path.exists(tarpath) - - extract_dir = os.path.join(tmp_path, "dir", "inexistent") - - with pytest.raises(ValueError, match=f"Problem during unpacking {tarpath}"): - tarball.uncompress(tarpath, extract_dir) - - def test_uncompress_tar(tmp_path, datadir): """Unpack supported tarball into an existent folder should be ok @@ -152,7 +137,6 @@ assert os.path.exists(tarpath) extract_dir = os.path.join(tmp_path, filename) - os.makedirs(extract_dir, exist_ok=True) tarball.uncompress(tarpath, extract_dir) @@ -234,7 +218,6 @@ assert os.path.exists(zippath) extract_dir = os.path.join(tmp_path, filename) - os.makedirs(extract_dir, exist_ok=True) tarball.uncompress(zippath, extract_dir)