1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-18 01:46:05 +08:00

Refetch local metadata cache if corruption is detected

Addresses one of the points in https://github.com/ppy/osu/issues/31496.

Not going to lie, this is mostly best-effort stuff (while the refetch is
happening, metadata lookups using the local source *will* fail), but I
see this as a marginal scenario anyways.
This commit is contained in:
Bartłomiej Dach 2025-01-14 11:19:17 +01:00
parent 75d1fab6d0
commit b0c0c98c5d
No known key found for this signature in database

View File

@ -114,6 +114,15 @@ namespace osu.Game.Beatmaps
}
}
}
catch (SqliteException sqliteException) when (sqliteException.SqliteErrorCode == 11 || sqliteException.SqliteErrorCode == 26) // SQLITE_CORRUPT, SQLITE_NOTADB
{
// only attempt purge & refetch if there is no other refetch in progress
if (cacheDownloadRequest == null)
{
tryPurgeCache();
prepareLocalCache();
}
}
catch (Exception ex)
{
logForModel(beatmapInfo.BeatmapSet, $@"Cached local retrieval for {beatmapInfo} failed with {ex}.");
@ -125,6 +134,22 @@ namespace osu.Game.Beatmaps
return false;
}
private void tryPurgeCache()
{
log(@"Local metadata cache is corrupted; attempting purge.");
try
{
File.Delete(storage.GetFullPath(cache_database_name));
}
catch (Exception ex)
{
log($@"Failed to purge local metadata cache: {ex}");
}
log(@"Local metadata cache purged due to corruption.");
}
private SqliteConnection getConnection() =>
new SqliteConnection(string.Concat(@"Data Source=", storage.GetFullPath(@"online.db", true)));