From abce62dd4f505bf2f8e2ebc975288f48bfae2344 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 23 Nov 2019 21:05:37 -0600 Subject: [PATCH] Avoid running into problems from a GC hole in runtimes that don't support fast span. Support for .NET Framework probably needs to be removed soon. Having runtime support for CreateSpan has turned out to be rather useful. --- src/LibHac/Fs/FileSystemClientUtils.cs | 3 ++- src/LibHac/FsSystem/FileSystemExtensions.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/LibHac/Fs/FileSystemClientUtils.cs b/src/LibHac/Fs/FileSystemClientUtils.cs index 0165f354..3a26c0df 100644 --- a/src/LibHac/Fs/FileSystemClientUtils.cs +++ b/src/LibHac/Fs/FileSystemClientUtils.cs @@ -111,13 +111,14 @@ namespace LibHac.Fs bool ignoreCase = searchOptions.HasFlag(SearchOptions.CaseInsensitive); bool recurse = searchOptions.HasFlag(SearchOptions.RecurseSubdirectories); - DirectoryEntry dirEntry = default; fs.OpenDirectory(out DirectoryHandle sourceHandle, path, OpenDirectoryMode.All).ThrowIfFailure(); using (sourceHandle) { while (true) { + DirectoryEntry dirEntry = default; + fs.ReadDirectory(out long entriesRead, SpanHelpers.AsSpan(ref dirEntry), sourceHandle); if (entriesRead == 0) break; diff --git a/src/LibHac/FsSystem/FileSystemExtensions.cs b/src/LibHac/FsSystem/FileSystemExtensions.cs index d640b39b..5b0471a5 100644 --- a/src/LibHac/FsSystem/FileSystemExtensions.cs +++ b/src/LibHac/FsSystem/FileSystemExtensions.cs @@ -79,12 +79,13 @@ namespace LibHac.FsSystem bool recurse = searchOptions.HasFlag(SearchOptions.RecurseSubdirectories); IFileSystem fs = fileSystem; - DirectoryEntry dirEntry = default; fileSystem.OpenDirectory(out IDirectory directory, path, OpenDirectoryMode.All).ThrowIfFailure(); while (true) { + DirectoryEntry dirEntry = default; + directory.Read(out long entriesRead, SpanHelpers.AsSpan(ref dirEntry)).ThrowIfFailure(); if (entriesRead == 0) break;