From 00fa1f4f314eceac8cdc7bd092846e6cb0b411d6 Mon Sep 17 00:00:00 2001
From: NolanB <nboukachab@teklia.com>
Date: Mon, 28 Nov 2022 15:55:44 +0100
Subject: [PATCH] publishing a folder containing subfolders

---
 arkindex_worker/worker/training.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/arkindex_worker/worker/training.py b/arkindex_worker/worker/training.py
index c53cffee..4a739288 100644
--- a/arkindex_worker/worker/training.py
+++ b/arkindex_worker/worker/training.py
@@ -30,7 +30,9 @@ FileSize = NewType("FileSize", int)
 
 
 @contextmanager
-def create_archive(path: DirPath) -> Tuple[Path, Hash, FileSize, Hash]:
+def create_archive(
+    path: DirPath, use_parent_folder: bool = False
+) -> Tuple[Path, Hash, FileSize, Hash]:
     """
     Create a tar archive from the files at the given location then compress it to a zst archive.
 
@@ -52,10 +54,12 @@ def create_archive(path: DirPath) -> Tuple[Path, Hash, FileSize, Hash]:
     # Files hierarchy ifs kept in the archive.
     file_list = []
     with tarfile.open(path_to_tar_archive, "w") as tar:
-        for p in path.glob("**/*"):
-            x = p.relative_to(path)
-            tar.add(p, arcname=x, recursive=False)
-            file_list.append(p)
+        if use_parent_folder:
+            # Only publish contents of the given folder without parent folder
+            tar.add(path, arcname=".")
+        else:
+            tar.add(path)
+        file_list = [member for member in tar.getnames() if os.path.isfile(member)]
 
     # Sort by path
     file_list.sort()
-- 
GitLab