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

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

Merged
merged 6 commits into from
Aug 16, 2023

Conversation

6t8k
Copy link
Contributor

@6t8k 6t8k commented Nov 26, 2022

  • Without this proposed change, if the path held by root_dir does not exist, or is not a directory, then CPython >3.10.5 will create an empty archive, so introduce an explicit check for it being a directory. shutil.make_archive() may then raise FileNotFoundError or NotADirectoryError before proceeding to call the internal format-specific archive creation function, as was formerly (implicitly) caused by os.chdir(root_dir), restoring CPython <=3.10.5 behavior.
  • For consistency, decided to raise the exception in dry run mode too
  • Add corresponding regression tests for both the _make_tarball() and _make_zipfile() scenario: although the former, unlike the latter, may already cause NotADirectoryError or FileNotFoundError to be raised with respect to root_dir without this proposed change, an empty archive will still be created. On the other hand, _make_zipfile(), is able to create an empty archive while not raising any exceptions, so test it as well, even though make_archive() would otherwise already be covered by test_make_tarfile_rootdir_nodir(), which runs regardless of zlib availability.

@6t8k
Copy link
Contributor Author

6t8k commented Nov 26, 2022

Will look into the failed Windows tests later.

…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 Author

6t8k commented Nov 27, 2022

@giampaolo if I'm not mistaken, the CODEOWNERS lines for ftplib and shutil seem to be missing a * suffix and do not seem to match the respective files as a result.

P.S.: I acknowledge [1], [2] and won't force-push here any longer, sorry.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating an empty archive without raising an exception is definitely a bug. Leaving an empty archive and raising an exception is more in a grey area, but in any case it is better to not create it if we can to detect an error earlier.

@6t8k
Copy link
Contributor Author

6t8k commented Jan 30, 2023

Thanks for the review! I addressed the findings.

@6t8k 6t8k requested review from serhiy-storchaka and removed request for giampaolo January 30, 2023 20:34
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Thank you for your response and sorry for the delay. This issue fell off my radar.

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Aug 16, 2023
@serhiy-storchaka serhiy-storchaka merged commit a86df29 into python:main Aug 16, 2023
@miss-islington
Copy link
Contributor

Thanks @6t8k for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @6t8k and @serhiy-storchaka, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker a86df298df5b02e2d69ea6879e9ed10a7adb85d0 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request 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>
@bedevere-bot
Copy link

GH-107998 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 bug and security fixes label Aug 16, 2023
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request 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>
@bedevere-bot
Copy link

GH-107999 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Aug 16, 2023
@serhiy-storchaka serhiy-storchaka removed their assignment Aug 16, 2023
serhiy-storchaka added a commit that referenced this pull request 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 pull request 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>
@6t8k 6t8k deleted the gh-99203 branch August 16, 2023 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants