Skip to content

Commit

Permalink
[delete-map] adds deletion of map file
Browse files Browse the repository at this point in the history
  • Loading branch information
KyreusR authored and kdankert committed Nov 17, 2023
1 parent 3284c6b commit 162934d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/EvoSC.Common/Services/MapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ public async Task<IEnumerable<IMap>> AddMapsAsync(List<MapStream> mapStreams)
public async Task RemoveMapAsync(long mapId)
{
await _mapRepository.RemoveMapAsync(mapId);
var map = await this.GetMapByIdAsync(mapId);

if (map == null) return;

var filePath = Path.Combine(_config.Path.Maps, "EvoSC", map.FilePath);
if (!File.Exists(filePath))
{
_logger.LogWarning("Tried to delete map which doesn't exists on the filesystem: {filePath}", filePath);
return;
}

try
{
File.Delete(filePath);
}
catch (Exception e)
{
_logger.LogError(e, "An exception occurred while trying to delete a map file.");
throw;
}
}

public async Task AddCurrentMapListAsync()
Expand Down
4 changes: 3 additions & 1 deletion tests/EvoSC.Common.Tests/Services/MapServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,12 @@ public async Task Remove_Map_Removes_Map()
Id = 123,
ExternalId = "1337",
Name = "snippens dream",
Uid = "Uid"
Uid = "Uid",
FilePath = "FilePath"
};
_mapRepository.Setup(m => m.GetMapByIdAsync(It.IsAny<long>()))
.Returns(Task.FromResult((IMap?)map));
_config.SetupGet(config => config.Path.Maps).Returns("MapPath");

await _mapService.RemoveMapAsync(123);

Expand Down

0 comments on commit 162934d

Please sign in to comment.