mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix EnsureApplicationSaveData failing if the temp save already exists
This commit is contained in:
parent
4e23465982
commit
0a96e8d623
3 changed files with 122 additions and 41 deletions
|
@ -677,6 +677,7 @@ public static class ApplicationSaveDataManagement
|
||||||
if (ResultFs.PathAlreadyExists.Includes(rc))
|
if (ResultFs.PathAlreadyExists.Includes(rc))
|
||||||
{
|
{
|
||||||
// Nothing to do if the save already exists.
|
// Nothing to do if the save already exists.
|
||||||
|
rc.Catch().Handle();
|
||||||
}
|
}
|
||||||
else if (ResultFs.UsableSpaceNotEnough.Includes(rc))
|
else if (ResultFs.UsableSpaceNotEnough.Includes(rc))
|
||||||
{
|
{
|
||||||
|
@ -686,6 +687,7 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,6 +708,7 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,8 +745,14 @@ public static class ApplicationSaveDataManagement
|
||||||
|
|
||||||
requiredSize += temporaryStorageSize;
|
requiredSize += temporaryStorageSize;
|
||||||
}
|
}
|
||||||
|
else if (ResultFs.PathAlreadyExists.Includes(rc))
|
||||||
|
{
|
||||||
|
// Nothing to do if the save already exists.
|
||||||
|
rc.Catch().Handle();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -776,6 +785,7 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc.Miss();
|
return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -789,7 +799,10 @@ public static class ApplicationSaveDataManagement
|
||||||
}
|
}
|
||||||
|
|
||||||
outRequiredSize = requiredSize;
|
outRequiredSize = requiredSize;
|
||||||
return ResultFs.UsableSpaceNotEnough.Log();
|
|
||||||
|
rc = ResultFs.UsableSpaceNotEnough.Log();
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result ExtendApplicationSaveData(this FileSystemClient fs, out long outRequiredSize,
|
public static Result ExtendApplicationSaveData(this FileSystemClient fs, out long outRequiredSize,
|
||||||
|
|
|
@ -26,7 +26,14 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
// EnsureApplicationSaveData should do nothing the second time it is called
|
||||||
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
void AssertSaveExists()
|
||||||
|
{
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
||||||
|
|
||||||
|
@ -38,6 +45,7 @@ public class ApplicationSaveDataManagementTests
|
||||||
Assert.Equal(Utility.ConvertAccountUidToFsUserId(userId), info[0].UserId);
|
Assert.Equal(Utility.ConvertAccountUidToFsUserId(userId), info[0].UserId);
|
||||||
Assert.Equal(SaveDataType.Account, info[0].Type);
|
Assert.Equal(SaveDataType.Account, info[0].Type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void EnsureApplicationSaveData_CreatesDeviceSaveData()
|
public static void EnsureApplicationSaveData_CreatesDeviceSaveData()
|
||||||
|
@ -54,7 +62,13 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
void AssertSaveExists()
|
||||||
|
{
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
||||||
|
|
||||||
|
@ -66,6 +80,7 @@ public class ApplicationSaveDataManagementTests
|
||||||
Assert.Equal(InvalidUserId, info[0].UserId);
|
Assert.Equal(InvalidUserId, info[0].UserId);
|
||||||
Assert.Equal(SaveDataType.Device, info[0].Type);
|
Assert.Equal(SaveDataType.Device, info[0].Type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void EnsureApplicationSaveData_CreatesBcatCacheStorage()
|
public static void EnsureApplicationSaveData_CreatesBcatCacheStorage()
|
||||||
|
@ -81,7 +96,13 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
void AssertSaveExists()
|
||||||
|
{
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User);
|
||||||
|
|
||||||
|
@ -93,6 +114,7 @@ public class ApplicationSaveDataManagementTests
|
||||||
Assert.Equal(InvalidUserId, info[0].UserId);
|
Assert.Equal(InvalidUserId, info[0].UserId);
|
||||||
Assert.Equal(SaveDataType.Bcat, info[0].Type);
|
Assert.Equal(SaveDataType.Bcat, info[0].Type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void EnsureApplicationSaveData_CreatesTemporaryStorage()
|
public static void EnsureApplicationSaveData_CreatesTemporaryStorage()
|
||||||
|
@ -108,7 +130,13 @@ public class ApplicationSaveDataManagementTests
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
Assert.Success(fs.EnsureApplicationSaveData(out _, applicationId, in controlProperty, in userId));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
void AssertSaveExists()
|
||||||
|
{
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.Temporary);
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.Temporary);
|
||||||
|
|
||||||
|
@ -120,6 +148,8 @@ public class ApplicationSaveDataManagementTests
|
||||||
Assert.Equal(InvalidUserId, info[0].UserId);
|
Assert.Equal(InvalidUserId, info[0].UserId);
|
||||||
Assert.Equal(SaveDataType.Temporary, info[0].Type);
|
Assert.Equal(SaveDataType.Temporary, info[0].Type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void EnsureApplicationSaveData_NeedsExtension_IsExtended()
|
public static void EnsureApplicationSaveData_NeedsExtension_IsExtended()
|
||||||
{
|
{
|
||||||
|
@ -180,7 +210,13 @@ public class ApplicationSaveDataManagementTests
|
||||||
|
|
||||||
Assert.Success(fs.EnsureApplicationCacheStorage(out _, out CacheStorageTargetMedia target, applicationId,
|
Assert.Success(fs.EnsureApplicationCacheStorage(out _, out CacheStorageTargetMedia target, applicationId,
|
||||||
in controlProperty));
|
in controlProperty));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
Assert.Success(fs.EnsureApplicationCacheStorage(out _, out target, applicationId, in controlProperty));
|
||||||
|
AssertSaveExists();
|
||||||
|
|
||||||
|
void AssertSaveExists()
|
||||||
|
{
|
||||||
Assert.Equal(CacheStorageTargetMedia.SdCard, target);
|
Assert.Equal(CacheStorageTargetMedia.SdCard, target);
|
||||||
|
|
||||||
using var iterator = new UniqueRef<SaveDataIterator>();
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
|
@ -193,6 +229,7 @@ public class ApplicationSaveDataManagementTests
|
||||||
Assert.Equal(applicationId, info[0].ProgramId);
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
Assert.Equal(SaveDataType.Cache, info[0].Type);
|
Assert.Equal(SaveDataType.Cache, info[0].Type);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void EnsureApplicationCacheStorage_SdCardNotAvailable_CreatesCacheStorageOnBis()
|
public static void EnsureApplicationCacheStorage_SdCardNotAvailable_CreatesCacheStorageOnBis()
|
||||||
|
|
|
@ -339,6 +339,37 @@ public class SaveDataManagement
|
||||||
Assert.Equal(mainProgramId, info[0].ProgramId);
|
Assert.Equal(mainProgramId, info[0].ProgramId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateTemporaryStorage_DoesNotExist_SaveIsCreated()
|
||||||
|
{
|
||||||
|
long availableSize = 0x220000;
|
||||||
|
|
||||||
|
var applicationId = new Ncm.ApplicationId(1);
|
||||||
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
||||||
|
|
||||||
|
Assert.Success(fs.CreateTemporaryStorage(applicationId, 0, availableSize, SaveDataFlags.None));
|
||||||
|
|
||||||
|
using var iterator = new UniqueRef<SaveDataIterator>();
|
||||||
|
fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.Temporary);
|
||||||
|
|
||||||
|
var info = new SaveDataInfo[2];
|
||||||
|
iterator.Get.ReadSaveDataInfo(out long entriesRead, info);
|
||||||
|
|
||||||
|
Assert.Equal(1, entriesRead);
|
||||||
|
Assert.Equal(applicationId, info[0].ProgramId);
|
||||||
|
Assert.Equal(SaveDataType.Temporary, info[0].Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateTemporaryStorage_AlreadyExists_ReturnsPathAlreadyExists()
|
||||||
|
{
|
||||||
|
var applicationId = new Ncm.ApplicationId(1);
|
||||||
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
||||||
|
|
||||||
|
Assert.Success(fs.CreateTemporaryStorage(applicationId, 0, 0x400000, SaveDataFlags.None));
|
||||||
|
Assert.Result(ResultFs.PathAlreadyExists, fs.CreateTemporaryStorage(applicationId, 0, 0x400000, SaveDataFlags.None));
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DeleteSaveData_DoesNotExist_ReturnsTargetNotFound()
|
public void DeleteSaveData_DoesNotExist_ReturnsTargetNotFound()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue