From 903942b2f4125985698042bb4868443450027c93 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Wed, 25 Jan 2023 23:27:40 -0700 Subject: [PATCH] Fix a bug when ensuring bcat saves exist --- .../Fs/ApplicationSaveDataManagement.cs | 2 +- .../ApplicationSaveDataManagementTests.cs | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/LibHac/Fs/ApplicationSaveDataManagement.cs b/src/LibHac/Fs/ApplicationSaveDataManagement.cs index 79cbca43..8cc48fac 100644 --- a/src/LibHac/Fs/ApplicationSaveDataManagement.cs +++ b/src/LibHac/Fs/ApplicationSaveDataManagement.cs @@ -210,7 +210,7 @@ public static class ApplicationSaveDataManagement if (bcatDeliveryCacheStorageSize > 0) { - Result res = SaveDataFilter.Make(out SaveDataFilter filter, programId: default, SaveDataType.Bcat, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Bcat, userId: default, saveDataId: default, index: default); if (res.IsFailure()) return res.Miss(); diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs index 5b394ca1..16716c48 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs @@ -45,6 +45,35 @@ public class ApplicationSaveDataManagementTests Assert.Equal(SaveDataType.Account, info[0].Type); } } + + [Fact] + public static void EnsureApplicationSaveData_CreatesMultipleAccountSaveData_AllSavesExist() + { + FileSystemClient fs = FileSystemServerFactory.CreateClient(true); + + var userId = new Uid(2, 3); + + var controlProperty = new ApplicationControlProperty + { + UserAccountSaveDataSize = 0x1000, + UserAccountSaveDataJournalSize = 0x1000 + }; + + Assert.Success(fs.EnsureApplicationSaveData(out _, new Ncm.ApplicationId(11), in controlProperty, in userId)); + Assert.Success(fs.EnsureApplicationSaveData(out _, new Ncm.ApplicationId(12), in controlProperty, in userId)); + AssertSaveExists(); + + void AssertSaveExists() + { + using var iterator = new UniqueRef(); + fs.OpenSaveDataIterator(ref iterator.Ref, SaveDataSpaceId.User); + + var info = new SaveDataInfo[3]; + Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info)); + + Assert.Equal(2, entriesRead); + } + } [Fact] public static void EnsureApplicationSaveData_CreatesDeviceSaveData() @@ -81,6 +110,35 @@ public class ApplicationSaveDataManagementTests } } + [Fact] + public static void EnsureApplicationSaveData_CreatesMultipleDeviceSaveData_AllSavesExist() + { + FileSystemClient fs = FileSystemServerFactory.CreateClient(true); + + var userId = new Uid(2, 3); + + var controlProperty = new ApplicationControlProperty + { + DeviceSaveDataSize = 0x1000, + DeviceSaveDataJournalSize = 0x1000 + }; + + Assert.Success(fs.EnsureApplicationSaveData(out _, new Ncm.ApplicationId(11), in controlProperty, in userId)); + Assert.Success(fs.EnsureApplicationSaveData(out _, new Ncm.ApplicationId(12), in controlProperty, in userId)); + AssertSaveExists(); + + void AssertSaveExists() + { + using var iterator = new UniqueRef(); + fs.OpenSaveDataIterator(ref iterator.Ref, SaveDataSpaceId.User); + + var info = new SaveDataInfo[3]; + Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info)); + + Assert.Equal(2, entriesRead); + } + } + [Fact] public static void EnsureApplicationSaveData_CreatesBcatCacheStorage() { @@ -115,6 +173,34 @@ public class ApplicationSaveDataManagementTests } } + [Fact] + public static void EnsureApplicationSaveData_CreatesMultipleBcatCacheStorages_AllSavesExist() + { + FileSystemClient fs = FileSystemServerFactory.CreateClient(true); + + var userId = new Uid(2, 3); + + var controlProperty = new ApplicationControlProperty + { + BcatDeliveryCacheStorageSize = 0x1000 + }; + + Assert.Success(fs.EnsureApplicationSaveData(out _, new Ncm.ApplicationId(11), in controlProperty, in userId)); + Assert.Success(fs.EnsureApplicationSaveData(out _, new Ncm.ApplicationId(12), in controlProperty, in userId)); + AssertSaveExists(); + + void AssertSaveExists() + { + using var iterator = new UniqueRef(); + fs.OpenSaveDataIterator(ref iterator.Ref, SaveDataSpaceId.User); + + var info = new SaveDataInfo[3]; + Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info)); + + Assert.Equal(2, entriesRead); + } + } + [Fact] public static void EnsureApplicationSaveData_CreatesTemporaryStorage() {