mirror of
https://github.com/ppy/osu.git
synced 2025-02-14 01:33:20 +08:00
Merge pull request #1831 from peppy/fix-import-context-state
Fix errors on import
This commit is contained in:
commit
494b1893e9
@ -102,15 +102,26 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
public Func<Storage> GetStableStorage { private get; set; }
|
||||
|
||||
public BeatmapManager(Storage storage, Func<OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
|
||||
private void refreshImportContext()
|
||||
{
|
||||
createContext = context;
|
||||
lock (importContextLock)
|
||||
{
|
||||
importContext?.Value?.Dispose();
|
||||
|
||||
importContext = new Lazy<OsuDbContext>(() =>
|
||||
{
|
||||
var c = createContext();
|
||||
c.Database.AutoTransactionsEnabled = false;
|
||||
return c;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public BeatmapManager(Storage storage, Func<OsuDbContext> context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
|
||||
{
|
||||
createContext = context;
|
||||
|
||||
refreshImportContext();
|
||||
|
||||
beatmaps = createBeatmapStore(context);
|
||||
files = new FileStore(context, storage);
|
||||
@ -175,13 +186,16 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
e = e.InnerException ?? e;
|
||||
Logger.Error(e, $@"Could not import beatmap set ({Path.GetFileName(path)})");
|
||||
refreshImportContext();
|
||||
}
|
||||
}
|
||||
|
||||
notification.State = ProgressNotificationState.Completed;
|
||||
}
|
||||
|
||||
private readonly Lazy<OsuDbContext> importContext;
|
||||
private readonly object importContextLock = new object();
|
||||
|
||||
private Lazy<OsuDbContext> importContext;
|
||||
|
||||
/// <summary>
|
||||
/// Import a beatmap from an <see cref="ArchiveReader"/>.
|
||||
@ -190,7 +204,7 @@ namespace osu.Game.Beatmaps
|
||||
public BeatmapSetInfo Import(ArchiveReader archiveReader)
|
||||
{
|
||||
// let's only allow one concurrent import at a time for now.
|
||||
lock (importContext)
|
||||
lock (importContextLock)
|
||||
{
|
||||
var context = importContext.Value;
|
||||
|
||||
@ -315,7 +329,7 @@ namespace osu.Game.Beatmaps
|
||||
/// <param name="beatmapSet">The beatmap set to delete.</param>
|
||||
public void Delete(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
lock (importContext)
|
||||
lock (importContextLock)
|
||||
{
|
||||
var context = importContext.Value;
|
||||
|
||||
@ -378,7 +392,7 @@ namespace osu.Game.Beatmaps
|
||||
if (beatmapSet.Protected)
|
||||
return;
|
||||
|
||||
lock (importContext)
|
||||
lock (importContextLock)
|
||||
{
|
||||
var context = importContext.Value;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user