Skip to content

shutil.make_archive does not follow symlinks for zip archives #81782

Closed as duplicate

Description

@KevinTeague
BPO 37601
Nosy @giampaolo, @tarekziade, @serhiy-storchaka, @tirkarthi

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2019-07-16.00:15:38.140>
labels = ['type-feature', 'library', '3.9']
title = 'shutil.make_archive does not follow symlinks for zip archives'
updated_at = <Date 2019-07-16.10:27:32.414>
user = 'https://bugs.python.org/KevinTeague'

bugs.python.org fields:

activity = <Date 2019-07-16.10:27:32.414>
actor = 'xtreak'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2019-07-16.00:15:38.140>
creator = 'Kevin Teague'
dependencies = []
files = []
hgrepos = []
issue_num = 37601
keywords = []
message_count = 2.0
messages = ['347996', '348013']
nosy_count = 5.0
nosy_names = ['giampaolo.rodola', 'tarek', 'serhiy.storchaka', 'xtreak', 'Kevin Teague']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue37601'
versions = ['Python 3.9']

Activity

  1. KevinTeague commented on Jul 16, 2019

    KevinTeaguemannequin
    MannequinAuthor

    Zip archives created with shutil.make_archive will not follow symlinks.

    The shutil._make_zipfile uses os.walk:

    for dirpath, dirnames, filenames in os.walk(base_dir)
    

    os.walk has the followlinks parameter:

    for dirpath, dirnames, filenames in os.walk(base_dir, followlinks=True)
    

    Setting followlinks to True will include symlinks in a zip archive.

    Could a followlinks parameter be added to shutil.make_archive?

  2. added
    3.7 (EOL)
    stdlib
    on Jul 16, 2019
  3. added
    3.9 (EOL)
    type-feature
    and removed
    3.7 (EOL)
    on Jul 16, 2019
  4. tirkarthi commented on Jul 16, 2019

    @tirkarthi
    Member

    This looks like a reasonable addition to me. Other APIs in shutil have follow_symlinks parameter.

    ➜ /tmp ls -al sym
    total 0
    drwxr-xr-x 3 karthikeyansingaravelan staff 102 Jul 16 15:52 .
    drwxr-xr-x 58 karthikeyansingaravelan staff 1972 Jul 16 15:52 ..
    -rw-r--r-- 1 karthikeyansingaravelan staff 0 Jul 16 15:05 a

    ➜ /tmp ls -al foo
    total 8
    drwxr-xr-x 5 karthikeyansingaravelan staff 170 Jul 16 15:43 .
    drwxr-xr-x 58 karthikeyansingaravelan staff 1972 Jul 16 15:52 ..
    -rw-r--r-- 1 karthikeyansingaravelan staff 0 Jul 16 15:00 a
    -rw-r--r-- 1 karthikeyansingaravelan staff 0 Jul 16 15:00 b
    lrwxr-xr-x 1 karthikeyansingaravelan staff 8 Jul 16 15:04 c -> /tmp/sym

    # Using zip in Mac and zipfile module

    ➜ /tmp python3 -m zipfile -c cmd.zip foo/*
    ➜ /tmp python3 -m zipfile -l cmd.zip
    File Name Modified Size
    a 2019-07-16 15:00:04 0
    b 2019-07-16 15:00:10 0
    c/ 2019-07-16 15:52:06 0
    c/a 2019-07-16 15:05:46 0

    # Using make_archive

    ➜ /tmp python3 -c "import shutil; shutil.make_archive('make_archive', 'zip', 'foo')"
    ➜ /tmp python3 -m zipfile -l make_archive.zip
    File Name Modified Size
    c/ 2019-07-16 15:52:06 0
    a 2019-07-16 15:00:04 0
    b 2019-07-16 15:00:10 0

  5. transferred this issue fromon Apr 10, 2022
  6. picnixz commented on Oct 7, 2025

    @picnixz
    Member

    Since #139679 is a broader issue and request, I'm going to close this one as a duplicate, while forwarding the previous message on consistency.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.9 (EOL)stdlibtype-feature

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions