This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: shutil.make_archive does not follow symlinks for zip archives
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Kevin Teague, giampaolo.rodola, serhiy.storchaka, tarek, xtreak
Priority: normal Keywords:

Created on 2019-07-16 00:15 by Kevin Teague, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg347996 - (view) Author: Kevin Teague (Kevin Teague) Date: 2019-07-16 00:15
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?
msg348013 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-07-16 10:27
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
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81782
2019-07-16 10:27:32xtreaksetnosy: + xtreak, serhiy.storchaka
messages: + msg348013
2019-07-16 00:22:35xtreaksettype: enhancement
versions: + Python 3.9, - Python 3.7
2019-07-16 00:22:04xtreaksetnosy: + giampaolo.rodola, tarek
2019-07-16 00:15:38Kevin Teaguecreate