Skip to content

Commit 2ac3717

Browse files
committed
Merge branch 'fix/archive_contains_empty_name_directory' into 'main'
fix: empty name directory in archive Closes PACMAN-1195 See merge request espressif/idf-component-manager!559
2 parents d0b9ca6 + eb148d2 commit 2ac3717

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

idf_component_tools/archive_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ def pack_archive(source_dir: t.Union[str, Path], archive_filepath: str) -> None:
114114
"""Create tar+gzip archive"""
115115
try:
116116
with tarfile.open(archive_filepath, 'w:gz') as archive:
117-
archive.add(source_dir, arcname='')
117+
archive.add(source_dir, arcname='./')
118118
except tarfile.TarError:
119119
raise ArchiveError(f'{archive_filepath} is not a valid tar archive')

tests/test_archive_tools.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
1+
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
33

44
import os
55
import shutil
6+
import tarfile
67
import tempfile
78
from filecmp import dircmp
89

@@ -12,6 +13,7 @@
1213
ArchiveError,
1314
get_format_from_path,
1415
is_known_format,
16+
pack_archive,
1517
unpack_archive,
1618
unpack_tar,
1719
unpack_zip,
@@ -76,3 +78,19 @@ def test_unpack_archive(self, archive_path):
7678

7779
finally:
7880
shutil.rmtree(tempdir)
81+
82+
def test_pack_archive_creates_valid_relative_tar(self, tmp_path):
83+
source_dir = tmp_path / 'test_component'
84+
source_dir.mkdir()
85+
(source_dir / 'file.txt').touch()
86+
archive_file = tmp_path / 'archive'
87+
pack_archive(source_dir, archive_file)
88+
89+
assert archive_file.exists()
90+
91+
with tarfile.open(archive_file, 'r:gz') as tar:
92+
names = tar.getnames()
93+
94+
# Verify: no absolute paths, files stored at top-level (relative './')
95+
assert all(not n.startswith('/') for n in names)
96+
assert './file.txt' in names

0 commit comments

Comments
 (0)