From 63fb61398ca97e869c998abf1c3fb7aa4dc9cae5 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Thu, 18 Jan 2024 17:18:33 +0100 Subject: [PATCH 1/2] Don't convert symlinks in audeer.extract_archive() --- audeer/core/io.py | 3 --- tests/test_io.py | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/audeer/core/io.py b/audeer/core/io.py index b4a7efa..158ab3b 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -314,9 +314,6 @@ def extract_archive( ['a.txt'] """ - archive = safe_path(archive) - destination = safe_path(destination) - if not os.path.exists(archive): raise FileNotFoundError( errno.ENOENT, diff --git a/tests/test_io.py b/tests/test_io.py index 072eb28..645e960 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -32,7 +32,7 @@ def tree(tmpdir, request): @pytest.mark.parametrize( - "tree, root, files, archive_create, archive_extract, destination, " "expected", + "tree, root, files, archive_create, archive_extract, destination, expected", [ ( # empty [], @@ -340,6 +340,19 @@ def test_archives( assert not os.path.exists(archive_extract) +def test_archives_symlink(tmpdir): + # Create folder with files and symlink to folder + folder = audeer.mkdir(tmpdir, "folder") + file = audeer.touch(folder, "file.txt") + link = os.path.join(tmpdir, "link") + os.symlink(folder, link) + archive = os.path.join(tmpdir, "archive.zip") + + audeer.create_archive(link, [file], archive) + result = audeer.extract_archive(archive, link) + assert result == ["file.txt"] + + @pytest.mark.parametrize( "path,ext,basename", [ From efd4f1e2a8fdd6e8aae3cefcc19993a2997a90b1 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Thu, 18 Jan 2024 17:20:52 +0100 Subject: [PATCH 2/2] Use follow_symlink=False --- audeer/core/io.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/audeer/core/io.py b/audeer/core/io.py index 158ab3b..c06fcc0 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -314,6 +314,9 @@ def extract_archive( ['a.txt'] """ + archive = safe_path(archive, follow_symlink=False) + destination = safe_path(destination, follow_symlink=False) + if not os.path.exists(archive): raise FileNotFoundError( errno.ENOENT,