#1714: apply suggestions for preventing addition of objects with similar uuid

This commit is contained in:
Czar Echavez
2023-08-09 15:15:45 +01:00
parent 572f457231
commit cf241366dc
2 changed files with 8 additions and 2 deletions

View File

@@ -95,7 +95,13 @@ class FileSystem(SimComponent):
:type: folder_name: str
"""
folder = FileSystemFolder(name=folder_name)
self.folders[folder.uuid] = folder
if folder.uuid in self.folders:
# iterate until a folder with a non-matching uuid is added
# which is VERY unlikely but it'll be weird if it happens twice
return self.create_folder(folder_name=folder_name)
else:
self.folders[folder.uuid] = folder
return folder
def delete_file(self, file: Optional[FileSystemFile] = None):

View File

@@ -26,7 +26,7 @@ class FileSystemFolder(FileSystemItem):
raise Exception(f"Invalid file: {file}")
# check if file with id already exists in folder
if self.get_file_by_id(file.uuid) is not None:
if file.uuid in self.files:
_LOGGER.debug(f"File with id {file.uuid} already exists in folder")
else:
# add to list