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: Add support for symlinks to zipfile
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Henry Schreiner, alanmcintyre, bochecha, eryksun, ldoktor, serhiy.storchaka, twouters
Priority: normal Keywords: patch

Created on 2016-06-14 11:55 by ldoktor, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
zipfile-symlink.patch ldoktor, 2016-06-14 11:55 zipfile-symlink-v1 review
zipfile-symlink.patch ldoktor, 2016-06-15 10:08 zipfile-symlink-v2 review
Messages (4)
msg268552 - (view) Author: Lukáš Doktor (ldoktor) Date: 2016-06-14 11:55
Currently the zipfile library extracts all files as simple files, even though it contains the information of the file attributes. This patch uses them to detect if the original file was a symlink and creates it when there is a support for symlink creation.
msg268562 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-06-14 15:23
os.symlink needs the target_is_directory argument on Windows. Maybe extract() can search for the link target in namelist() to determine if it's a directory (i.e. ends in "/"). Note that the flag gets set automatically if the target exists, so this is only a problem when a link is extracted before the target.

Also, I think it should fall back on creating a regular file if os.symlink raises OSError. On Windows this occurs if the user doesn't have SeCreateSymbolicLinkPrivilege. os.symlink raises a plain OSError in this case; no errno/winerror is set. (I don't know why it doesn't simply call CreateSymbolicLink and raise an exception for the last error, which would be ERROR_PRIVILEGE_NOT_HELD.)
msg268616 - (view) Author: Lukáš Doktor (ldoktor) Date: 2016-06-15 10:08
Hello Eryk,

thank you for the prompt response. I have only checked that using python2.6 on `wine` and there was no `os.symlink` support there. I'm not sure how to reasonably handle the `dir` flag for Windows as theoretically the symlink can point out of the zip file.

Do you know what happens when the symlink `dir` flag is set inappropriately? I guess it silently continues, but the link wont work, right?

Well I added the `except OSError` part, please let me know, whether this version is acceptable. The situation could only be better as without this patch both OSs are stuck with text files instead of symlinks, this way at least on Linux it should work properly.
msg295014 - (view) Author: Mathieu Bridon (bochecha) * Date: 2017-06-02 12:53
Do note that extracting a zipfile with symlinks might lead to unexpected results, for example if the path pointed to is outside of the extract dir.

Maybe the behaviour introduced in this patch should not be the default, but instead `extract` and `extractall` could take a new flag `preserve_symlinks` which would default to False? (to keep the same default as today)
History
Date User Action Args
2022-04-11 14:58:32adminsetgithub: 71505
2022-01-19 16:59:26Henry Schreinersetnosy: + Henry Schreiner
2021-03-18 22:11:51eryksunsetversions: + Python 3.10, - Python 3.6
2017-06-02 12:53:28bochechasetnosy: + bochecha
messages: + msg295014
2016-06-15 10:08:44ldoktorsetfiles: + zipfile-symlink.patch

messages: + msg268616
2016-06-14 15:23:20eryksunsetnosy: + eryksun
messages: + msg268562
2016-06-14 12:08:40SilentGhostsetnosy: + twouters, alanmcintyre, serhiy.storchaka

versions: + Python 3.6, - Python 2.7
2016-06-14 11:55:34ldoktorcreate