Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zip distribution does not include leading directory #2672

Merged
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
10 changes: 8 additions & 2 deletions src/assemble_workflow/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,17 @@ def __extract__(self, dest: str) -> None:

def __build__(self, name: str, dest: str) -> None:
with ZipFile(name, "w", zipfile.ZIP_DEFLATED) as zip:
rootlen = len(self.archive_path) + 1
# root : /tmp/tmp********/opensearch-<version+qualifier>
# leadingdir : opensearch-<version+qualifier>
# root no leading dir: /tmp/tmp********/
# This is to preserve the leading directory `opensearch-<version+qualifier>` in zip
rootlen = len(self.archive_path)
leadingdirlen = len(os.path.basename(self.archive_path))
noleadingdirlen = rootlen - leadingdirlen
for base, _, files in os.walk(self.archive_path):
for file in files:
fn = os.path.join(base, file)
zip.write(fn, fn[rootlen:])
zip.write(fn, fn[noleadingdirlen:])


class DistRpm(Dist):
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_assemble_workflow/test_bundle_opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,5 @@ def test_bundle_package_zip(self) -> None:
with patch("shutil.copyfile") as mock_copyfile:
bundle.package(os.path.dirname(__file__))
mock_zipfile_open.assert_called_with("opensearch.zip", "w", zipfile.ZIP_DEFLATED)
mock_zipfile_write.assert_called_with(os.path.join(bundle.tmp_dir.name, "opensearch-1.3.0", "opensearch.txt"), "opensearch.txt")
mock_zipfile_write.assert_called_with(os.path.join(bundle.tmp_dir.name, "opensearch-1.3.0", "opensearch.txt"), os.path.join("opensearch-1.3.0", "opensearch.txt"))
self.assertEqual(mock_copyfile.call_count, 1)