mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix a bug in ConvertToFsCommonPath
This commit is contained in:
parent
655fed169a
commit
279f86d910
2 changed files with 44 additions and 2 deletions
|
@ -292,7 +292,7 @@ public static class MountUtility
|
|||
if (mountNameLength + commonPathLength > commonPathBuffer.Length)
|
||||
return ResultFs.TooLongPath.Log();
|
||||
|
||||
StringUtils.Copy(commonPathBuffer.Slice(commonPathLength), subPath);
|
||||
StringUtils.Copy(commonPathBuffer.Slice(mountNameLength), subPath);
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
using LibHac.Common;
|
||||
using System;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.Fs.Shim;
|
||||
using LibHac.Tests.Fs.FileSystemClientTests;
|
||||
using LibHac.Tools.Fs;
|
||||
using LibHac.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace LibHac.Tests.Fs.FsaTests;
|
||||
|
@ -32,4 +35,43 @@ public class MountUtilityTests
|
|||
Assert.Success(fs.MountSdCard(mountName.ToU8Span()));
|
||||
Assert.Result(ResultFs.InvalidMountName, fs.GetEntryType(out _, path.ToU8Span()));
|
||||
}
|
||||
|
||||
private class TestCommonMountNameGenerator : ICommonMountNameGenerator
|
||||
{
|
||||
public void Dispose() { }
|
||||
|
||||
public Result GenerateCommonMountName(Span<byte> nameBuffer)
|
||||
{
|
||||
ReadOnlySpan<byte> mountName = "@Test"u8;
|
||||
|
||||
// Add 2 for the mount name separator and null terminator
|
||||
int requiredNameBufferSize = StringUtils.GetLength(mountName, PathTool.MountNameLengthMax) + 2;
|
||||
|
||||
Assert.True(nameBuffer.Length >= requiredNameBufferSize);
|
||||
|
||||
var sb = new U8StringBuilder(nameBuffer);
|
||||
sb.Append(mountName).Append(StringTraits.DriveSeparator);
|
||||
|
||||
Assert.Equal(sb.Length, requiredNameBufferSize - 1);
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConvertToFsCommonPath_MountedWithCommonPath_ReturnsCommonPath()
|
||||
{
|
||||
FileSystemClient fs = FileSystemServerFactory.CreateClient(true);
|
||||
|
||||
using var fileSystem = new UniqueRef<IFileSystem>(new InMemoryFileSystem());
|
||||
using var mountNameGenerator = new UniqueRef<ICommonMountNameGenerator>(new TestCommonMountNameGenerator());
|
||||
Assert.Success(fs.Register("mount"u8, ref fileSystem.Ref, ref mountNameGenerator.Ref));
|
||||
|
||||
byte[] outputPath = new byte[100];
|
||||
Assert.Success(fs.ConvertToFsCommonPath(new U8SpanMutable(outputPath), "mount:/entry1/entry2"u8));
|
||||
|
||||
string expected = "@Test:/entry1/entry2";
|
||||
string actual = StringUtils.Utf8ZToString(outputPath);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue