python / cpython

The Python programming language
https://www.python.org
Other
63.4k stars 30.36k forks source link

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

Open ab2d10cb-35fb-4143-be63-ed0c5d91f174 opened 5 years ago

ab2d10cb-35fb-4143-be63-ed0c5d91f174 commented 5 years ago
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: ```python assignee = None closed_at = None created_at = labels = ['type-feature', 'library', '3.9'] title = 'shutil.make_archive does not follow symlinks for zip archives' updated_at = user = 'https://bugs.python.org/KevinTeague' ``` bugs.python.org fields: ```python activity = actor = 'xtreak' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = 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'] ```

ab2d10cb-35fb-4143-be63-ed0c5d91f174 commented 5 years ago

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?

tirkarthi commented 5 years ago

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