Revert disallowing imports with no files

While it is logical that we want this, from a testing perspective this is a bit of a nightmare to fix. Let's revisit at a later point in time.
This commit is contained in:
Dean Herbert
2021-10-21 13:35:26 +09:00
parent 7a1be99999
commit 59b7210efa
3 changed files with 28 additions and 23 deletions

View File

@ -48,11 +48,12 @@ namespace osu.Game.Tests.Skins.IO
});
[Test]
public Task TestEmptyImportFails() => runSkinTest(osu =>
public Task TestEmptyImportImportsWithFilename() => runSkinTest(async osu =>
{
Assert.ThrowsAsync<InvalidOperationException>(() => loadSkinIntoOsu(osu, new ZipArchiveReader(createEmptyOsk(), "test skin.osk")));
var import1 = await loadSkinIntoOsu(osu, new ZipArchiveReader(createEmptyOsk(), "test skin.osk"));
return Task.CompletedTask;
// When the import filename matches it shouldn't be appended.
assertCorrectMetadata(import1, "test skin", "Unknown", osu);
});
#endregion

View File

@ -322,22 +322,22 @@ namespace osu.Game.Database
.OrderBy(f => f.Filename)
.ToArray();
if (hashableFiles.Length == 0)
throw new InvalidOperationException("Attempted to hash an archive with no files");
// for now, concatenate all hashable files in the set to create a unique hash.
MemoryStream hashable = new MemoryStream();
foreach (TFileModel file in hashableFiles)
if (hashableFiles.Length > 0)
{
using (Stream s = Files.Store.GetStream(file.FileInfo.StoragePath))
s.CopyTo(hashable);
// for now, concatenate all hashable files in the set to create a unique hash.
MemoryStream hashable = new MemoryStream();
foreach (TFileModel file in hashableFiles)
{
using (Stream s = Files.Store.GetStream(file.FileInfo.StoragePath))
s.CopyTo(hashable);
}
if (hashable.Length > 0)
return hashable.ComputeSHA2Hash();
}
if (hashable.Length > 0)
return hashable.ComputeSHA2Hash();
return item.Hash;
return generateFallbackHash();
}
/// <summary>
@ -707,10 +707,10 @@ namespace osu.Game.Database
s.CopyTo(hashable);
}
if (hashable.Length == 0)
throw new InvalidOperationException("Attempted to hash an archive with no files");
if (hashable.Length > 0)
return hashable.ComputeSHA2Hash();
return hashable.ComputeSHA2Hash();
return generateFallbackHash();
}
/// <summary>
@ -923,6 +923,14 @@ namespace osu.Game.Database
#endregion
private static string generateFallbackHash()
{
// if a hash could no be generated from file content, presume a unique / new import.
// therefore, let's use a guaranteed unique hash.
// this doesn't follow the SHA2 hashing schema intentionally, so such entries on the data store can be identified.
return Guid.NewGuid().ToString();
}
private string getValidFilename(string filename)
{
foreach (char c in Path.GetInvalidFileNameChars())

View File

@ -157,10 +157,6 @@ namespace osu.Game.Skinning
protected override string ComputeHash(SkinInfo item, ArchiveReader reader = null)
{
// we will be adding a hashable file below, but this is only useful if there are any other files in the skin.
if (item.Files.Count == 0)
throw new InvalidOperationException("Attempted to hash an archive with no files");
var instance = GetSkin(item);
// This function can be run on fresh import or save. The logic here ensures a skin.ini file is in a good state for both operations.