Skip to content

Commit 1bd3b42

Browse files
committed
[NE03B-121] Use max compression level for snapshot zip archive
1 parent f4c6f60 commit 1bd3b42

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

mgmtworker/cloudify_system_workflows/snapshots/snapshot_create.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import queue
55
import shutil
66
import tempfile
7+
import zipfile
78
from collections import defaultdict
89
from pathlib import Path
910
from typing import Any
@@ -292,7 +293,33 @@ def _prepare_output_dir(self, tenant_name: str):
292293

293294
def _create_archive(self):
294295
ctx.logger.debug('Creating snapshot archive')
295-
shutil.make_archive(self._archive_dest, 'zip', self._temp_dir)
296+
base_name = os.fspath(self._archive_dest)
297+
root_dir = self._temp_dir
298+
zip_filename = base_name + ".zip"
299+
archive_dir = os.path.dirname(base_name)
300+
if not os.path.exists(archive_dir):
301+
ctx.logger.info("creating %s", archive_dir)
302+
os.makedirs(archive_dir)
303+
with zipfile.ZipFile(
304+
zip_filename,
305+
"w",
306+
compression=zipfile.ZIP_DEFLATED,
307+
compresslevel=9,
308+
) as zf:
309+
base_dir = os.path.join(root_dir, os.curdir)
310+
base_dir = os.path.normpath(base_dir)
311+
for dirpath, dirnames, filenames in os.walk(base_dir):
312+
arcdirpath = os.path.relpath(dirpath, root_dir)
313+
for name in sorted(dirnames):
314+
path = os.path.join(dirpath, name)
315+
arcname = os.path.join(arcdirpath, name)
316+
zf.write(path, arcname)
317+
for name in filenames:
318+
path = os.path.join(dirpath, name)
319+
path = os.path.normpath(path)
320+
if os.path.isfile(path):
321+
arcname = os.path.join(arcdirpath, name)
322+
zf.write(path, arcname)
296323

297324
def _upload_archive(self):
298325
ctx.logger.debug('Uploading archive to manager')

0 commit comments

Comments
 (0)