Fix node file delete action

This commit is contained in:
Marek Wolan
2024-01-31 13:50:20 +00:00
parent 41a7f83887
commit 83db5b1eb5
3 changed files with 31 additions and 4 deletions

View File

@@ -303,8 +303,7 @@ class NodeFileDeleteAction(NodeFileAbstractAction):
file_name = self.manager.get_file_name_by_idx(node_idx=node_id, folder_idx=folder_id, file_idx=file_id)
if node_name is None or folder_name is None or file_name is None:
return ["do_nothing"]
return ["do_nothing"]
# return ["network", "node", node_name, "file_system", "delete", "file", folder_name, file_name]
return ["network", "node", node_name, "file_system", "delete", "file", folder_name, file_name]
class NodeFileRepairAction(NodeFileAbstractAction):

View File

@@ -78,12 +78,12 @@ class FileSystem(SimComponent):
self._delete_manager.add_request(
name="file",
request_type=RequestType(
func=lambda request, context: self.delete_file_by_id(folder_uuid=request[0], file_uuid=request[1])
func=lambda request, context: self.delete_file(folder_name=request[0], file_name=request[1])
),
)
self._delete_manager.add_request(
name="folder",
request_type=RequestType(func=lambda request, context: self.delete_folder_by_id(folder_uuid=request[0])),
request_type=RequestType(func=lambda request, context: self.delete_folder(folder_name=request[0])),
)
rm.add_request(
name="delete",

View File

@@ -526,3 +526,31 @@ def test_node_file_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAge
game.step()
assert file.health_status == FileSystemItemHealthStatus.CORRUPT
assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT
def test_node_file_delete_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
"""Test that a file can be deleted by the agent."""
game, agent = game_and_agent
# 1: assert the file is there
client_1 = game.simulation.network.get_node_by_hostname("client_1")
file = client_1.file_system.get_file("downloads", "cat.png")
assert file is not None
assert not file.deleted
# 2: delete the file
action = (
"NODE_FILE_DELETE",
{
"node_id": 0, # client_1
"folder_id": 0, # downloads
"file_id": 0, # cat.png
},
)
agent.store_action(action)
game.step()
# 3. Check that the file is not there any more
assert not client_1.file_system.get_file("downloads", "cat.png")
# 3.1 (but with the reference to the original file, we can check that deleted flag is True )
assert file.deleted