1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00

Fix second case of empty beatmaps being reported to sentry as errors

This commit is contained in:
Dean Herbert 2022-06-27 15:29:01 +09:00
parent da61d0547f
commit 13c8d33009

View File

@ -18,7 +18,6 @@ using osu.Game.Database;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.IO.Archives; using osu.Game.IO.Archives;
using osu.Game.Models;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -49,7 +48,7 @@ namespace osu.Game.Beatmaps
protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default) protected override void Populate(BeatmapSetInfo beatmapSet, ArchiveReader? archive, Realm realm, CancellationToken cancellationToken = default)
{ {
if (archive != null) if (archive != null)
beatmapSet.Beatmaps.AddRange(createBeatmapDifficulties(beatmapSet.Files, realm)); beatmapSet.Beatmaps.AddRange(createBeatmapDifficulties(beatmapSet, realm));
foreach (BeatmapInfo b in beatmapSet.Beatmaps) foreach (BeatmapInfo b in beatmapSet.Beatmaps)
{ {
@ -200,23 +199,32 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// Create all required <see cref="BeatmapInfo"/>s for the provided archive. /// Create all required <see cref="BeatmapInfo"/>s for the provided archive.
/// </summary> /// </summary>
private List<BeatmapInfo> createBeatmapDifficulties(IList<RealmNamedFileUsage> files, Realm realm) private List<BeatmapInfo> createBeatmapDifficulties(BeatmapSetInfo beatmapSet, Realm realm)
{ {
var beatmaps = new List<BeatmapInfo>(); var beatmaps = new List<BeatmapInfo>();
foreach (var file in files.Where(f => f.Filename.EndsWith(".osu", StringComparison.OrdinalIgnoreCase))) foreach (var file in beatmapSet.Files.Where(f => f.Filename.EndsWith(".osu", StringComparison.OrdinalIgnoreCase)))
{ {
using (var memoryStream = new MemoryStream(Files.Store.Get(file.File.GetStoragePath()))) // we need a memory stream so we can seek using (var memoryStream = new MemoryStream(Files.Store.Get(file.File.GetStoragePath()))) // we need a memory stream so we can seek
{ {
IBeatmap decoded; IBeatmap decoded;
using (var lineReader = new LineBufferedReader(memoryStream, true)) using (var lineReader = new LineBufferedReader(memoryStream, true))
{
if (lineReader.PeekLine() == null)
{
LogForModel(beatmapSet, $"No content found in beatmap file {file.Filename}.");
continue;
}
decoded = Decoder.GetDecoder<Beatmap>(lineReader).Decode(lineReader); decoded = Decoder.GetDecoder<Beatmap>(lineReader).Decode(lineReader);
}
string hash = memoryStream.ComputeSHA2Hash(); string hash = memoryStream.ComputeSHA2Hash();
if (beatmaps.Any(b => b.Hash == hash)) if (beatmaps.Any(b => b.Hash == hash))
{ {
Logger.Log($"Skipping import of {file.Filename} due to duplicate file content.", LoggingTarget.Database); LogForModel(beatmapSet, $"Skipping import of {file.Filename} due to duplicate file content.");
continue; continue;
} }
@ -227,7 +235,7 @@ namespace osu.Game.Beatmaps
if (ruleset?.Available != true) if (ruleset?.Available != true)
{ {
Logger.Log($"Skipping import of {file.Filename} due to missing local ruleset {decodedInfo.Ruleset.OnlineID}.", LoggingTarget.Database); LogForModel(beatmapSet, $"Skipping import of {file.Filename} due to missing local ruleset {decodedInfo.Ruleset.OnlineID}.");
continue; continue;
} }