Skip to content
Open
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
2 changes: 2 additions & 0 deletions sdk/basyx/aas/adapter/aasx.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ def rename_file(self, old_name: str, new_name: str) -> str:
if new_name == old_name:
return new_name
file_hash, file_content_type = self._name_map[old_name]
self._store_refcount[file_hash] -= 1
del self._name_map[old_name]
return self._assign_unique_name(new_name, file_hash, file_content_type)

Expand All @@ -889,6 +890,7 @@ def _assign_unique_name(self, name: str, sha: bytes, content_type: str) -> str:
while True:
if new_name not in self._name_map:
self._name_map[new_name] = (sha, content_type)
self._store_refcount[sha] += 1
return new_name
elif self._name_map[new_name] == (sha, content_type):
return new_name
Expand Down
18 changes: 18 additions & 0 deletions sdk/test/adapter/aasx/test_aasx.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ def test_supplementary_file_container(self) -> None:
with self.assertRaises(KeyError):
container.write_file(duplicate_file, file_content)

def test_supplementary_file_container_refcount(self) -> None:
container = aasx.DictSupplementaryFileContainer()
data = b"test content"
name1 = container.add_file("/file1.bin", io.BytesIO(data), "application/octet-stream")
name2 = container.add_file("/file2.bin", io.BytesIO(data), "application/octet-stream")
content_hash = container.get_sha256(name1)

# Both names point to same content — backing store must be present
self.assertIn(content_hash, container._store)

# Deleting one reference must NOT free the backing store
container.delete_file(name1)
self.assertIn(content_hash, container._store)

# Deleting the last reference must free the backing store
container.delete_file(name2)
self.assertNotIn(content_hash, container._store)


class AASXWriterTest(unittest.TestCase):
def test_writing_reading_example_aas(self) -> None:
Expand Down
Loading