Move InMemoryFileSystem, PathParser, PathTools

This commit is contained in:
Alex Barney 2021-12-19 01:35:45 -07:00
parent d0a1d98885
commit a289059ecf
25 changed files with 29 additions and 153 deletions

View file

@ -1,6 +1,5 @@
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSystem;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

View file

@ -5,7 +5,6 @@ using LibHac.Common;
using LibHac.Common.Keys;
using LibHac.Crypto;
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.Kernel;
using LibHac.Tools.FsSystem;

View file

@ -1,123 +0,0 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.Util;
namespace LibHac.Common;
[DebuggerDisplay("{ToString()}")]
internal ref struct PathBuilder
{
private Span<byte> _buffer;
private int _pos;
public int Length
{
get => _pos;
set
{
Debug.Assert(value >= 0);
Debug.Assert(value <= Capacity);
_pos = value;
}
}
public int Capacity => _buffer.Length - 1;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PathBuilder(Span<byte> buffer)
{
_buffer = buffer;
_pos = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Result Append(byte value)
{
int pos = _pos;
if (pos >= Capacity)
{
return ResultFs.TooLongPath.Log();
}
_buffer[pos] = value;
_pos = pos + 1;
return Result.Success;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Result Append(ReadOnlySpan<byte> value)
{
int pos = _pos;
if (pos + value.Length >= Capacity)
{
return ResultFs.TooLongPath.Log();
}
value.CopyTo(_buffer.Slice(pos));
_pos = pos + value.Length;
return Result.Success;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Result AppendWithPrecedingSeparator(byte value)
{
int pos = _pos;
if (pos + 1 >= Capacity)
{
// Append the separator if there's enough space
if (pos < Capacity)
{
_buffer[pos] = (byte)'/';
_pos = pos + 1;
}
return ResultFs.TooLongPath.Log();
}
_buffer[pos] = (byte)'/';
_buffer[pos + 1] = value;
_pos = pos + 2;
return Result.Success;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Result GoUpLevels(int count)
{
Debug.Assert(count > 0);
int separators = 0;
int pos = _pos - 1;
for (; pos >= 0; pos--)
{
if (PathTools.IsDirectorySeparator(_buffer[pos]))
{
separators++;
if (separators == count) break;
}
}
if (separators != count) return ResultFs.DirectoryUnobtainable.Log();
_pos = pos;
return Result.Success;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Terminate()
{
if (_buffer.Length > _pos)
{
_buffer[_pos] = 0;
}
}
public override string ToString()
{
return StringUtils.Utf8ZToString(_buffer.Slice(0, Length));
}
}

View file

@ -3,6 +3,7 @@ using System.IO;
using System.Text;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.Tools.FsSystem;
using LibHac.Util;
namespace LibHac.FsSystem;

View file

@ -1,5 +1,5 @@
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.Tools.FsSystem;
namespace LibHac.Tools.Fs;

View file

@ -4,7 +4,6 @@ using System.Collections.Generic;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tools.FsSystem;
namespace LibHac.Tools.Fs;

View file

@ -2,11 +2,13 @@
using System.Diagnostics;
using System.IO;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tools.FsSystem;
using LibHac.Util;
using Path = LibHac.Fs.Path;
namespace LibHac.Fs;
namespace LibHac.Tools.Fs;
/// <summary>
/// A filesystem stored in-memory. Mainly used for testing.

View file

@ -2,7 +2,6 @@
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Util;
namespace LibHac.Tools.FsSystem;

View file

@ -3,7 +3,6 @@ using System.Diagnostics;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tools.Fs;
using LibHac.Util;

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
namespace LibHac.Tools.FsSystem;

View file

@ -1,7 +1,7 @@
using System;
using System.Diagnostics;
namespace LibHac.FsSystem;
namespace LibHac.Tools.FsSystem;
/// <summary>
/// Enumerates a file or directory path one segment at a time.
@ -82,4 +82,4 @@ public ref struct PathParser
/// </summary>
/// <returns><see langword="true"/> if the current path segment is the final one.</returns>
public bool IsFinished() => _finished;
}
}

View file

@ -5,9 +5,10 @@ using System.Runtime.CompilerServices;
using LibHac.Common;
using LibHac.Diag;
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.Util;
namespace LibHac.FsSystem;
namespace LibHac.Tools.FsSystem;
public static class PathTools
{

View file

@ -2,7 +2,6 @@
using System.Runtime.InteropServices;
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.Util;
namespace LibHac.Tools.FsSystem.RomFs;

View file

@ -5,7 +5,6 @@ using System.Linq;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tools.Fs;
using LibHac.Util;

View file

@ -3,7 +3,6 @@ using System.IO;
using System.Runtime.InteropServices;
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.Util;
namespace LibHac.Tools.FsSystem.Save;

View file

@ -4,7 +4,6 @@ using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tools.Fs;
using LibHac.Tools.FsSystem;

View file

@ -1,6 +1,6 @@
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.Fs.Fsa;
using LibHac.Tests.Fs.IFileSystemTestBase;
using LibHac.Tools.Fs;
using LibHac.Tools.FsSystem;
namespace LibHac.Tests.Fs;

View file

@ -7,6 +7,7 @@ using LibHac.Fs.Fsa;
using LibHac.FsSrv;
using LibHac.FsSystem;
using LibHac.Tests.Fs.IFileSystemTestBase;
using LibHac.Tools.Fs;
using Xunit;
namespace LibHac.Tests.Fs;
@ -448,4 +449,4 @@ public class DirectorySaveDataFileSystemTests : CommittableIFileSystemTests
return Result.Success;
}
}
}

View file

@ -2,6 +2,7 @@
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSrv;
using LibHac.Tools.Fs;
namespace LibHac.Tests.Fs.FileSystemClientTests;
@ -53,4 +54,4 @@ public static class FileSystemServerFactory
{
return CreateHorizonImpl(true, out _);
}
}
}

View file

@ -1,6 +1,6 @@
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.Fs.Fsa;
using LibHac.Tests.Fs.IFileSystemTestBase;
using LibHac.Tools.Fs;
namespace LibHac.Tests.Fs;
@ -15,4 +15,4 @@ public class InMemoryFileSystemTests : IAttributeFileSystemTests
{
return new InMemoryFileSystem();
}
}
}

View file

@ -3,6 +3,7 @@ using LibHac.Common;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tools.Fs;
using LibHac.Util;
using Xunit;
@ -205,4 +206,4 @@ public class LayeredFileSystemTests
Assert.Success(directory.Get.GetEntryCount(out long entryCount));
Assert.Equal(0, entryCount);
}
}
}

View file

@ -3,6 +3,7 @@ using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSystem;
using LibHac.Tests.Fs.IFileSystemTestBase;
using LibHac.Tools.Fs;
using Xunit;
namespace LibHac.Tests.Fs;
@ -65,4 +66,4 @@ public class SubdirectoryFileSystemTestsRoot : IFileSystemTests
subFs.Initialize(in rootPath).ThrowIfFailure();
return subFs;
}
}
}

View file

@ -1,8 +1,8 @@
using LibHac.Bcat;
using LibHac.Common.Keys;
using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.FsSrv;
using LibHac.Tools.Fs;
namespace LibHac.Tests;
@ -32,4 +32,4 @@ public static class HorizonFactory
return horizon;
}
}
}

View file

@ -4,6 +4,7 @@ using LibHac.Fs;
using LibHac.Fs.Fsa;
using LibHac.Kvdb;
using LibHac.Tests.Fs.FileSystemClientTests;
using LibHac.Tools.Fs;
using Xunit;
using TTest = System.Int32;
@ -581,4 +582,4 @@ public class FlatMapKeyValueStoreTests
iterator.Next();
}
}
}
}

View file

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using LibHac.Common;
using LibHac.FsSystem;
using LibHac.Tools.FsSystem;
using LibHac.Util;
using Xunit;
@ -219,4 +219,4 @@ public class PathToolsTests
Assert.Equal(expected, actual);
}
}
}