Repository navigation
gh-162732: Propagate errors when traversing directories in shutil.make_archive(..., 'zip') - #162795
anisayakmitra-in wants to merge 1 commit into
Conversation
…il.make_archive(..., 'zip') When shutil.make_archive(..., 'zip') cannot list a source directory, propagate the OSError encountered during traversal rather than silently omitting files and creating an incomplete archive. Signed-off-by: ANISAYAK MITRA <266799942+anisayakmitra-in@users.noreply.github.com>
1cf14a8 to
cc8b97f
Compare
picnixz
left a comment
There was a problem hiding this comment.
I'm no longer sure that it's a real issue. I need more context about that on the issue, especially with the fact that we explicitly suppress an OSError when trying os.stat().
| logger.info("adding '%s'", base_dir) | ||
| for dirpath, dirnames, filenames in os.walk(base_dir): | ||
|
|
||
| def _onerror(err): |
There was a problem hiding this comment.
Why making it a private function? it doesn't make sense.
| try: | ||
| st = os.stat(path) | ||
| except OSError: | ||
| continue |
There was a problem hiding this comment.
Here, this looks like a deliberate choice for ignoring this specific OSError. Maybe this is actually the legitimate behavior? I think we need more careful investigation.
| @@ -0,0 +1,3 @@ | |||
| :func:`shutil.make_archive` with format ``"zip"`` now propagates any | |||
| :exc:`OSError` encountered when traversing source directories instead of | |||
There was a problem hiding this comment.
This is not true since there are some that are silenced.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
For now, I'm closing this. Please avoid using an LLM to address recent issues automatically. |
When
shutil.make_archive(..., 'zip')encounters an unreadable directory duringos.walk(base_dir), the defaultonerror=Noneinos.walksilently ignores the error and returns a truncated archive where unlisted directories appear empty. Other formats (such as tar) and command-line zip utilities raise when directories cannot be listed.This PR provides an
onerrorhandler in_make_zipfileto propagateOSError(e.g.PermissionError) when traversing source directories, matching tarball behavior and preventing silent data loss during archive creation.Closes gh-162732.