Skip to content

Conversation

cowgoesmoo69
Copy link

@cowgoesmoo69 cowgoesmoo69 commented Oct 9, 2025

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
Copy link

python-cla-bot bot commented Oct 9, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Oct 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant