Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't convert symlinks in audeer.extract_archive() #138

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions audeer/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ def extract_archive(
['a.txt']

"""
archive = safe_path(archive)
destination = safe_path(destination)
archive = safe_path(archive, follow_symlink=False)
destination = safe_path(destination, follow_symlink=False)

if not os.path.exists(archive):
raise FileNotFoundError(
Expand Down
15 changes: 14 additions & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
[],
Expand Down Expand Up @@ -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",
[
Expand Down