Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[delete-map] adds deletion of map file #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to be able to test the actual file deletion, but I can't think about a way to verify the file deletion was handled with the correct path. @snixtho What do you think?

}
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
Loading