Skip to content
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

Bug report: shutil.make_archive() makes empty archive file even when root_dir does not exists #99203

Closed
mski-iksm opened this issue Nov 7, 2022 · 3 comments · Fixed by #107998
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@mski-iksm
Copy link

mski-iksm commented Nov 7, 2022

Bug report

In python 3.10+, shutil.make_archive() makes empty archive file and does not raise any error even when root_dir does not exists.
In python -3.9, FileNotFoundError is raised with message [Errno 2] No such file or directory: ‘xxxxxxx’.

import shutil

shutil.make_archive(base_name='aaa_archive', root_dir="not_existing_dir", format="zip")
# This will raise FileNotFoundError in python ~3.9, where it doesn’t in 3.10~

I though making empty archive file is unnatural, so fixing it maybe good for backward compatibility.

I think this problem is caused in this line, where os.chdir(root_dir) is not called anymore.
In the previous code, os.chdir(root_dir) will raise FileNotFoundError when root_dir does not exists.
https://github.com/python/cpython/pull/93160/files#diff-db8ac59326160713929e0e1973aef54f0280fe9f154ef24d14244909a0e0689bL1084

I thought checking the existence of root_dir and raise FileNotFoundError when root_dir is not found, might be a good implementation to fix this problem.

Linked PRs

@mski-iksm mski-iksm added the type-bug An unexpected behavior, bug, or error label Nov 7, 2022
@sobolevn sobolevn added stdlib Python modules in the Lib dir 3.10 only security fixes 3.9 only security fixes 3.11 only security fixes 3.12 bugs and security fixes labels Nov 9, 2022
6t8k added a commit to 6t8k/cpython that referenced this issue Nov 27, 2022
…10.5 behavior

Restore following CPython <= 3.10.5 behavior of `shutil.make_archive()`
that went away as part of pythongh-93160:

Do not create an empty archive if `root_dir` is not a directory, and, in
that case, raise `FileNotFoundError` or `NotADirectoryError` regardless
of `format` choice. Beyond the brought-back behavior, the function may
now also raise these exceptions in `dry_run` mode.
@6t8k
Copy link
Contributor

6t8k commented Jan 29, 2023

Gentle ping:
@giampaolo @serhiy-storchaka @merwok

6t8k added a commit to 6t8k/cpython that referenced this issue Jan 30, 2023
@iritkatriel iritkatriel removed 3.10 only security fixes 3.9 only security fixes labels Apr 5, 2023
serhiy-storchaka pushed a commit that referenced this issue Aug 16, 2023
…avior (GH-99802)

Restore following CPython <= 3.10.5 behavior of shutil.make_archive()
that went away as part of gh-93160:

Do not create an empty archive if root_dir is not a directory, and, in
that case, raise FileNotFoundError or NotADirectoryError regardless
of format choice. Beyond the brought-back behavior, the function may
now also raise these exceptions in dry_run mode.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 16, 2023
….5 behavior (pythonGH-99802)

Restore following CPython <= 3.10.5 behavior of shutil.make_archive()
that went away as part of pythongh-93160:

Do not create an empty archive if root_dir is not a directory, and, in
that case, raise FileNotFoundError or NotADirectoryError regardless
of format choice. Beyond the brought-back behavior, the function may
now also raise these exceptions in dry_run mode.
(cherry picked from commit a86df29)

Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this issue Aug 16, 2023
…<= 3.10.5 behavior (pythonGH-99802)

Restore following CPython <= 3.10.5 behavior of shutil.make_archive()
that went away as part of pythongh-93160:

Do not create an empty archive if root_dir is not a directory, and, in
that case, raise FileNotFoundError or NotADirectoryError regardless
of format choice. Beyond the brought-back behavior, the function may
now also raise these exceptions in dry_run mode..
(cherry picked from commit a86df29)

Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
serhiy-storchaka added a commit that referenced this issue Aug 16, 2023
…0.5 behavior (GH-99802) (GH-107999)

Restore following CPython <= 3.10.5 behavior of shutil.make_archive()
that went away as part of gh-93160:

Do not create an empty archive if root_dir is not a directory, and, in
that case, raise FileNotFoundError or NotADirectoryError regardless
of format choice. Beyond the brought-back behavior, the function may
now also raise these exceptions in dry_run mode.
(cherry picked from commit a86df29)

Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
Yhg1s pushed a commit that referenced this issue Aug 16, 2023
…0.5 behavior (GH-99802) (#107998)

gh-99203: shutil.make_archive(): restore select CPython <= 3.10.5 behavior (GH-99802)

Restore following CPython <= 3.10.5 behavior of shutil.make_archive()
that went away as part of gh-93160:

Do not create an empty archive if root_dir is not a directory, and, in
that case, raise FileNotFoundError or NotADirectoryError regardless
of format choice. Beyond the brought-back behavior, the function may
now also raise these exceptions in dry_run mode.
(cherry picked from commit a86df29)

Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
@chrkr
Copy link

chrkr commented Apr 30, 2024

Would it be an idea to backport this fix to 3.10 as well? Because there is now a slight range of Python versions where using '' as the root_path does work (3.10.6 - 3.11.4) and it just so happens that using the 'latest' version of each release this fails in all versions except 3.10.

@merwok
Copy link
Member

merwok commented Apr 30, 2024

Only security fixes are accepted for 3.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
7 participants