Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Lib/shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,11 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0,
zf.write(base_dir, arcname)
if logger is not None:
logger.info("adding '%s'", base_dir)
for dirpath, dirnames, filenames in os.walk(base_dir):

def _onerror(err):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why making it a private function? it doesn't make sense.

raise err

for dirpath, dirnames, filenames in os.walk(base_dir, onerror=_onerror):
arcdirpath = dirpath
if root_dir is not None:
arcdirpath = os.path.relpath(arcdirpath, root_dir)
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,22 @@ def test_make_archive_owner_group(self):
owner='kjhkjhkjg', group='oihohoh')
self.assertTrue(os.path.isfile(res))

@support.requires_zlib()
def test_make_archive_zip_unreadable_dir(self):
root_dir, base_dir = self._create_files()
sub = os.path.join(root_dir, base_dir, 'sub')
base_name = os.path.join(self.mkdtemp(), 'archive')
orig_scandir = os.scandir

def fail_scandir(path='.'):
if os.path.normpath(str(path)) == os.path.normpath(sub):
raise PermissionError(f"Permission denied: {path!r}")
return orig_scandir(path)

with unittest.mock.patch('os.scandir', side_effect=fail_scandir):
with self.assertRaises(PermissionError):
make_archive(base_name, 'zip', root_dir, base_dir)


@support.requires_zlib()
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`shutil.make_archive` with format ``"zip"`` now propagates any
:exc:`OSError` encountered when traversing source directories instead of

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not true since there are some that are silenced.

silently producing an incomplete archive.
Loading