Skip to content

Commit 51b4087

Browse files
committed
adapter.aasx: Add rename_file to DictSupplementaryFileContainer
Before: There was no supported way to rename supplementary files in `DictSupplementaryFileContainer`. Workflow had to manipulate internals or create duplicates, making file handling error-prone. Now: A public rename operation preserves content de-duplication and resolves name conflicts, simplifying AASX read/write flows and reducing inconsistent mappings.
1 parent e622edc commit 51b4087

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

sdk/basyx/aas/adapter/aasx.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -824,15 +824,24 @@ def add_file(self, name: str, file: IO[bytes], content_type: str) -> str:
824824
if hash not in self._store:
825825
self._store[hash] = data
826826
self._store_refcount[hash] = 0
827-
name_map_data = (hash, content_type)
827+
return self._assign_unique_name(name, hash, content_type)
828+
829+
def rename_file(self, old_name: str, new_name: str) -> str:
830+
if old_name not in self._name_map:
831+
raise KeyError(f"File with name {old_name} not found in SupplementaryFileContainer.")
832+
if new_name == old_name:
833+
return new_name
834+
old_hash, old_ct = self._name_map[old_name]
835+
return self._assign_unique_name(new_name, old_hash, old_ct)
836+
837+
def _assign_unique_name(self, name: str, sha: bytes, content_type: str) -> str:
828838
new_name = name
829839
i = 1
830840
while True:
831841
if new_name not in self._name_map:
832-
self._name_map[new_name] = name_map_data
833-
self._store_refcount[hash] += 1
842+
self._name_map[new_name] = (sha, content_type)
834843
return new_name
835-
elif self._name_map[new_name] == name_map_data:
844+
elif self._name_map[new_name] == (sha, content_type):
836845
return new_name
837846
new_name = self._append_counter(name, i)
838847
i += 1

0 commit comments

Comments
 (0)