Add a function to specify that a returned Result is unused

This commit is contained in:
Alex Barney 2020-03-21 21:13:59 -07:00
parent cd5d46c81b
commit d1110392b4
4 changed files with 16 additions and 9 deletions

View File

@ -160,10 +160,10 @@ namespace LibHac.FsService
// Check if permissions allow deleting save data // Check if permissions allow deleting save data
} }
reader.Indexer.SetState(saveDataId, SaveDataState.Creating); rc = reader.Indexer.SetState(saveDataId, SaveDataState.Creating);
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;
reader.Indexer.Commit(); rc = reader.Indexer.Commit();
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;
} }
@ -406,7 +406,7 @@ namespace LibHac.FsService
// Revert changes if an error happened in the middle of creation // Revert changes if an error happened in the middle of creation
if (isDeleteNeeded) if (isDeleteNeeded)
{ {
DeleteSaveDataFileSystemImpl2(creationInfo.SpaceId, saveDataId); DeleteSaveDataFileSystemImpl2(creationInfo.SpaceId, saveDataId).IgnoreResult();
if (reader.IsInitialized && saveDataId != FileSystemServer.SaveIndexerId) if (reader.IsInitialized && saveDataId != FileSystemServer.SaveIndexerId)
{ {
@ -414,8 +414,8 @@ namespace LibHac.FsService
if (rc.IsSuccess() && value.SpaceId == creationInfo.SpaceId) if (rc.IsSuccess() && value.SpaceId == creationInfo.SpaceId)
{ {
reader.Indexer.Delete(saveDataId); reader.Indexer.Delete(saveDataId).IgnoreResult();
reader.Indexer.Commit(); reader.Indexer.Commit().IgnoreResult();
} }
} }
} }
@ -1151,7 +1151,7 @@ namespace LibHac.FsService
rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, SaveDataSpaceId.Temporary); rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, SaveDataSpaceId.Temporary);
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;
reader.Indexer.Reset(); reader.Indexer.Reset().IgnoreResult();
return Result.Success; return Result.Success;
} }

View File

@ -677,7 +677,8 @@ namespace LibHac.FsService
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;
baseFileSystem.EnsureDirectoryExists(contentDirPath.ToString()); rc = baseFileSystem.EnsureDirectoryExists(contentDirPath.ToString());
if (rc.IsFailure()) return rc;
rc = FsCreators.SubDirectoryFileSystemCreator.Create(out IFileSystem subDirFileSystem, rc = FsCreators.SubDirectoryFileSystemCreator.Create(out IFileSystem subDirFileSystem,
baseFileSystem, contentDirPath); baseFileSystem, contentDirPath);
@ -879,7 +880,7 @@ namespace LibHac.FsService
if (cacheExtraData) if (cacheExtraData)
{ {
// Missing extra data caching // todo: Missing extra data caching
} }
fileSystem = openReadOnly ? new ReadOnlyFileSystem(saveFs) : saveFs; fileSystem = openReadOnly ? new ReadOnlyFileSystem(saveFs) : saveFs;

View File

@ -42,7 +42,7 @@ namespace LibHac.FsService
SaveDataIndexerManager = new SaveDataIndexerManager(FsClient, SaveIndexerId); SaveDataIndexerManager = new SaveDataIndexerManager(FsClient, SaveIndexerId);
fsProxy.CleanUpTemporaryStorage(); fsProxy.CleanUpTemporaryStorage().IgnoreResult();
} }
/// <summary> /// <summary>

View File

@ -70,6 +70,11 @@ namespace LibHac
public bool IsSuccess() => _value == SuccessValue; public bool IsSuccess() => _value == SuccessValue;
public bool IsFailure() => !IsSuccess(); public bool IsFailure() => !IsSuccess();
/// <summary>
/// Specifies that the <see cref="Result"/> from a returned function is explicitly ignored.
/// </summary>
public void IgnoreResult() { }
public void ThrowIfFailure() public void ThrowIfFailure()
{ {
if (IsFailure()) if (IsFailure())
@ -212,6 +217,7 @@ namespace LibHac
/// <c>new Result.Base(ModuleFs, 2000, 2499)</c>. The property will need to have the aggressive inlining flag set like so: /// <c>new Result.Base(ModuleFs, 2000, 2499)</c>. The property will need to have the aggressive inlining flag set like so:
/// <c>public static Result.Base SdCardAccessFailed { [MethodImpl(MethodImplOptions.AggressiveInlining)] get =&gt; new Result.Base(ModuleFs, 2000, 2499); }</c> /// <c>public static Result.Base SdCardAccessFailed { [MethodImpl(MethodImplOptions.AggressiveInlining)] get =&gt; new Result.Base(ModuleFs, 2000, 2499); }</c>
/// </remarks> /// </remarks>
[DebuggerDisplay("{" + nameof(ToStringWithName) + "(),nq}")]
public struct Base public struct Base
{ {
private const int DescriptionEndBitsOffset = ReservedBitsOffset; private const int DescriptionEndBitsOffset = ReservedBitsOffset;