mirror of
https://github.com/ppy/osu.git
synced 2025-02-28 23:32:59 +08:00
Add import test with files to be filtered out
Add a test case reproducing the conditions encountered "in the wild" wherein a skin import would be performed incorrectly due to a __MACOSX resource fork directory present next to a directory with the actual skin files in the archive.
This commit is contained in:
parent
c8ffc134d4
commit
11acd177f1
@ -456,6 +456,60 @@ namespace osu.Game.Tests.Beatmaps.IO
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestImportWithIgnoredDirectoryInArchive()
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(nameof(TestImportWithIgnoredDirectoryInArchive)))
|
||||
{
|
||||
try
|
||||
{
|
||||
var osu = loadOsu(host);
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
string extractedFolder = $"{temp}_extracted";
|
||||
string dataFolder = Path.Combine(extractedFolder, "actual_data");
|
||||
string resourceForkFolder = Path.Combine(extractedFolder, "__MACOSX");
|
||||
string resourceForkFilePath = Path.Combine(resourceForkFolder, ".extracted");
|
||||
|
||||
Directory.CreateDirectory(dataFolder);
|
||||
Directory.CreateDirectory(resourceForkFolder);
|
||||
|
||||
using (var resourceForkFile = File.CreateText(resourceForkFilePath))
|
||||
{
|
||||
resourceForkFile.WriteLine("adding content so that it's not empty");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var zip = ZipArchive.Open(temp))
|
||||
zip.WriteToDirectory(dataFolder);
|
||||
|
||||
using (var zip = ZipArchive.Create())
|
||||
{
|
||||
zip.AddAllFromDirectory(extractedFolder);
|
||||
zip.SaveTo(temp, new ZipWriterOptions(CompressionType.Deflate));
|
||||
}
|
||||
|
||||
var imported = await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
||||
|
||||
ensureLoaded(osu);
|
||||
|
||||
Assert.IsFalse(imported.Files.Any(f => f.Filename.Contains("__MACOSX")), "Files contain resource fork folder, which should be ignored");
|
||||
Assert.IsFalse(imported.Files.Any(f => f.Filename.Contains("actual_data")), "Files contain common subfolder");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(extractedFolder, true);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
host.Exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string path = null)
|
||||
{
|
||||
var temp = path ?? TestResources.GetTestBeatmapForImport();
|
||||
|
Loading…
Reference in New Issue
Block a user