Hi!

tldr; I'm interested in having ZipFile's extract() method inverse to add()
where possible. I'm not sure about which API would be best to choose.


Firstly some context

Zip files created by ZipFile (from zipfile module) already store last
modification time and date and unix file mode of files. When files are
extracted, files and directories are always created with default
permissions and no other state of files is restored.

Permission behavior is not documented yet [1] and an enhancement request
exists for some time [2]. There have been couple of questions on
StackOverflow [3], [4], [5] with various level of robustness. There is even
a pull request [6] but it changes current behavior.


What others do?

Info-Zip's unzip[7] by default restores only "safe" permissions
- SUID/SGID/Sticky bits are cleared out. Unless explicitly requested with
-K option. Permissions of stored directories are not restored except under
Unix.

PKZIP's PKZIP[8] allows specification of a mask:

    [...] mask for files to be added or extracted. The mask specifies
permissions which
    should not be archived or restored on extraction.
    [...] The setuid, setgid, and sticky bits are set on extracted files
only if the permission
    option is used.

And in non-zip world - GNU tar preserves permissions when -p is specified
(default for superuser).

Python's tarfile - extractall() always preserves ownership, date, time and
permissions. Method extract() by default preserves the same but has
attribute set_attr to skip all of those.


Finally about ZipFile's interface enhancement

I *guess* it might not be good idea to change behaviour there was for
couple of releases/years now [9]. In zip world SUID/SGID/Sticky bits seems
to treated specially so I guess it might be good idea to stick with that
instead of imitating python's tar.

Patch [10] attached to one of the issue uses various constants. Is this a
good, pythonic, interface?

I'm rather thinking of adding new attributes to ZipFile class, extract()
and extractall() methods:
- set_mode = False (sets only regular modes)
- set_special_mode = False (sets only special permissions)

and later to be extended with:
- set_timestamp = False (sets modified time)
- set_owner = False (sets owner and group)



Pavol

--

[1] https://bugs.python.org/issue18262
[2] https://bugs.python.org/issue15795
[3] https://stackoverflow.com/q/434641/83400
[4] https://stackoverflow.com/q/3007233/83400
[5] https://stackoverflow.com/q/42326428/83400
[6] https://github.com/python/cpython/pull/17790
[7] See man unzip(1)
[8]
https://support.pkware.com/home/pkzip/pkzip-securezip-for-unix-linux/pkzip_securezip-for-unix_linux-users-guide/adding-files-to-an-archive-in-unix
[9] https://www.python.org/dev/peps/pep-0387/
[10] https://bugs.python.org/file34893/issue15795_test_and_doc_fixes.patch
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/TVAGGJGADBYBUJOCRU3ZLI555POY4VUA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to