Add safety against calling GetStableImportPaths when path doesn't exist

This commit is contained in:
Dean Herbert 2022-05-17 16:55:41 +09:00
parent adc7b61240
commit 30fdbc3de0
2 changed files with 16 additions and 4 deletions

View File

@ -24,8 +24,14 @@ namespace osu.Game.Database
/// <summary>
/// Select paths to import from stable where all paths should be absolute. Default implementation iterates all directories in <see cref="ImportFromStablePath"/>.
/// </summary>
protected virtual IEnumerable<string> GetStableImportPaths(Storage storage) => storage.GetDirectories(ImportFromStablePath)
.Select(path => storage.GetFullPath(path));
protected virtual IEnumerable<string> GetStableImportPaths(Storage storage)
{
if (!storage.ExistsDirectory(ImportFromStablePath))
return Enumerable.Empty<string>();
return storage.GetDirectories(ImportFromStablePath)
.Select(path => storage.GetFullPath(path));
}
protected readonly IModelImporter<TModel> Importer;

View File

@ -15,8 +15,14 @@ namespace osu.Game.Database
protected override string ImportFromStablePath => Path.Combine("Data", "r");
protected override IEnumerable<string> GetStableImportPaths(Storage storage)
=> storage.GetFiles(ImportFromStablePath).Where(p => Importer.HandledExtensions.Any(ext => Path.GetExtension(p)?.Equals(ext, StringComparison.OrdinalIgnoreCase) ?? false))
.Select(path => storage.GetFullPath(path));
{
if (!storage.ExistsDirectory(ImportFromStablePath))
return Enumerable.Empty<string>();
return storage.GetFiles(ImportFromStablePath)
.Where(p => Importer.HandledExtensions.Any(ext => Path.GetExtension(p)?.Equals(ext, StringComparison.OrdinalIgnoreCase) ?? false))
.Select(path => storage.GetFullPath(path));
}
public LegacyScoreImporter(IModelImporter<ScoreInfo> importer)
: base(importer)