New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shutil.make_archive should not need to chdir (alternatively: make shutil.make_archive thread-safe) #74696
Comments
Currently shutil.make_archive uses os.chdir, however there's no need for that. Everything that's done could be equally accomplished with path manipulation: https://github.com/python/cpython/blob/master/Lib/shutil.py#L773-L779 We should switch to using path manipulation in order to make shutil.make_archive thread safe. (Flag: This is probably a good bug for someone with Python skills interested in contributing to CPython!) |
Unfortunately this is not possible. The signature of functions registered with register_archive_format() doesn't support this. |
None of those functions are a public API, so changing them shouldn't be a problem IMO. |
Ugh, except via |register_archive_format|. |register_archive_format| could wrap callables passed to it to maintain the current behavior. |
It would be nice if there was at least a warning in the docs that make_archive is not thread-safe, and that if you have two threads creating archives that it's extremely likely you'll get erroneous results since the race condition lasts for the entire duration of the archive creation. |
Just wasted two hours for this. Can someone really update the documentation of it if this is not going to change. |
PR is added here: |
Just a note that this is still relevant. We still get Python users at work who run into this. (the documentation definitely helps, but often after the fact while debugging a WTF?! style failure) I wouldn't let We can detect when we're using an unknown externally registered format that is not chdir safe (anything unknown that came to us via |
Also a reality check: What code exists that uses |
Okay, I take this. |
…te a zip or tar archive in shutil.make_archive() It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None.
….make_archive() if possible It is no longer changed when create a zip or tar archive. It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None.
#93160 is a first step. It makes standard zip and tar archivers not changing the current working directory. In the following PR I'll make it supporting in custom archivers. |
….make_archive() if possible (pythonGH-93160) It is no longer changed when create a zip or tar archive. It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None. Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit fda4b2f06364ae5ef91ecd9c09e2af380c8b0b4c) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…archive() if possible (GH-93160) It is no longer changed when create a zip or tar archive. It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None. Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
….make_archive() if possible (pythonGH-93160) It is no longer changed when create a zip or tar archive. It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None. Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit fda4b2f06364ae5ef91ecd9c09e2af380c8b0b4c) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…archive() if possible (GH-93160) (GH-94105) It is no longer changed when create a zip or tar archive. It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None. Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit fda4b2f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…archive() if possible (GH-93160) (GH-94106) It is no longer changed when create a zip or tar archive. It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None. Co-authored-by: Éric <merwok@netwok.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit fda4b2f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@gpshead I'm +1 to deprecate |
I was going to extend It can be implemented either by adding a boolean parameter |
Sure, Serhiy. Greg's point is that this functionality looks unused so it's probably an unnecessary support burden. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: