Skip to content

gh-139679: Resolve symbolic links to directories when shutil.make_archive() is used to create a zip file - #139856

Open
cowgoesmoo69 wants to merge 18 commits into
python:mainfrom
cowgoesmoo69:shutil-default-zipfile-behaviour
Open

cowgoesmoo69 wants to merge 18 commits into
python:mainfrom
cowgoesmoo69:shutil-default-zipfile-behaviour

Conversation

@cowgoesmoo69

@cowgoesmoo69 cowgoesmoo69 commented Oct 9, 2025 •

Copy link
Copy Markdown

This aligns the default behaviour of shutil.make_archive() for creating zip files, with the default behaviour of command-line zip utilities on Linux/UNIX/Windows. Now, if a symbolic link to a directory is encountered when creating the list of files for the zip file, it is followed and the contents of the target directory included.

Docstring of shutil._make_zipfile() has been expanded to document the new behaviour and warn about the risk of infinite recursion that exists with os.walk().

test_shutil.py has been updated with tests to prove the new behaviour is working as expected. Explanation of how to avoid the test being skipped on Windows is included.

This causes symbolic links to both files and directories to be resolved and the link targets included in the resulting zipfile. This matches the default behaviour of command-line zip on Linux/UNIX systems (i.e. systems where filesystems supporting symbolic linking are likely to be present).
Docstring now describes the behaviour when symbolic links to files and directories are encountered.
Docstring now describes behaviour when hard links to files are encountered.
Improved readability and added comments to _create_files_symlinks() for making a test directory structure.

Expanded docstring for test_make_zipfile_symlink_behaviour to explain purpose of test and reasons why the test might be skipped in a Windows environment.

Updated test with try-finally for proper clean up of files after the test.
First line of docstring within a test gets printed out when test runs. No other tests appear to be doing that so switched to commented lines instead.
@python-cla-bot

python-cla-bot Bot commented Oct 9, 2025 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Oct 9, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant