Issue #24982: shutil.make_archive() with the "zip" format now adds entries

for directories (including empty directories) in ZIP file.
Added test for comparing shutil.make_archive() with the "zip" command.
This commit is contained in:
Serhiy Storchaka 2015-09-08 05:53:42 +03:00
commit 899f32fe1e
3 changed files with 43 additions and 6 deletions

View file

@ -679,7 +679,16 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
if not dry_run:
with zipfile.ZipFile(zip_filename, "w",
compression=zipfile.ZIP_DEFLATED) as zf:
path = os.path.normpath(base_dir)
zf.write(path, path)
if logger is not None:
logger.info("adding '%s'", path)
for dirpath, dirnames, filenames in os.walk(base_dir):
for name in sorted(dirnames):
path = os.path.normpath(os.path.join(dirpath, name))
zf.write(path, path)
if logger is not None:
logger.info("adding '%s'", path)
for name in filenames:
path = os.path.normpath(os.path.join(dirpath, name))
if os.path.isfile(path):