Uh oh!
There was an error while loading. Please reload this page.
gh-99203: shutil.make_archive(): restore select CPython <= 3.10.5 behavior - #99802
Conversation
Will look into the failed Windows tests later. |
…ehavior 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.
@giampaolo if I'm not mistaken, the P.S.: I acknowledge [1], [2] and won't force-push here any longer, sorry. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
6t8k
commented
Jan 30, 2023
Thanks for the review! I addressed the findings. |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM.
Thank you for your response and sorry for the delay. This issue fell off my radar.
miss-islington
commented
Aug 16, 2023
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
commented
Aug 16, 2023
Sorry, @6t8k and @serhiy-storchaka, I could not cleanly backport this to |
….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
commented
Aug 16, 2023
GH-107998 is a backport of this pull request to the 3.12 branch. |
…<= 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
commented
Aug 16, 2023
GH-107999 is a backport of this pull request to the 3.11 branch. |
…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>
…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>
root_dirdoes 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 raiseFileNotFoundErrororNotADirectoryErrorbefore proceeding to call the internal format-specific archive creation function, as was formerly (implicitly) caused byos.chdir(root_dir), restoring CPython <=3.10.5 behavior._make_tarball()and_make_zipfile()scenario: although the former, unlike the latter, may already causeNotADirectoryErrororFileNotFoundErrorto be raised with respect toroot_dirwithout 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 thoughmake_archive()would otherwise already be covered bytest_make_tarfile_rootdir_nodir(), which runs regardless of zlib availability.