From 9a5af82a28b6ea8994f5627a1a885d0fbe1a5d44 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sat, 24 Feb 2024 19:02:16 +0800 Subject: [PATCH] Save empty directories when exporting a project --- gns3server/controller/export_project.py | 5 +++++ tests/controller/test_export_project.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/gns3server/controller/export_project.py b/gns3server/controller/export_project.py index fc7226fe..a1652f19 100644 --- a/gns3server/controller/export_project.py +++ b/gns3server/controller/export_project.py @@ -83,6 +83,11 @@ async def export_project(zstream, project, temporary_dir, include_images=False, continue _patch_mtime(path) zstream.write(path, os.path.relpath(path, project._path)) + # save empty directories + for directory in dirs: + path = os.path.join(root, directory) + if not os.listdir(path): + zstream.write(path, os.path.relpath(path, project._path)) except FileNotFoundError as e: log.warning("Cannot export local file: {}".format(e)) continue diff --git a/tests/controller/test_export_project.py b/tests/controller/test_export_project.py index 973ed36e..9406afd7 100644 --- a/tests/controller/test_export_project.py +++ b/tests/controller/test_export_project.py @@ -111,6 +111,7 @@ async def test_export(tmpdir, project): f.write("HELLO") with open(os.path.join(path, "vm-1", "dynamips", "test_log.txt"), 'w+') as f: f.write("LOG") + os.makedirs(os.path.join(path, "vm-1", "dynamips", "empty-dir")) os.makedirs(os.path.join(path, "project-files", "snapshots")) with open(os.path.join(path, "project-files", "snapshots", "test"), 'w+') as f: f.write("WORLD") @@ -127,6 +128,7 @@ async def test_export(tmpdir, project): assert 'test.gns3' not in myzip.namelist() assert 'project.gns3' in myzip.namelist() + assert 'vm-1/dynamips/empty-dir/' in myzip.namelist() assert 'project-files/snapshots/test' not in myzip.namelist() assert 'vm-1/dynamips/test_log.txt' not in myzip.namelist()