Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Ramstack.FileSystem.Utilities;
/// <summary>
/// Provides extension methods for the <see cref="IEnumerable{T}"/>.
/// </summary>
public static class EnumerableExtensions
internal static class EnumerableExtensions
{
/// <summary>
/// Converts an enumerable sequence to an async-enumerable sequence.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Runtime.CompilerServices;

namespace Ramstack.FileSystem.Utilities;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.FileSystem.Abstractions/VirtualPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static bool IsNormalized(ReadOnlySpan<char> path)
for (var j = 1; (uint)j < (uint)path.Length; j++)
{
var ch = path[j];
if (ch == '\\' || ch == '/' && prior == '/')
if (ch == '\\' || (ch == '/' && prior == '/'))
return false;

if (ch == '.' && prior == '/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<Compile Include="..\Ramstack.FileSystem.Abstractions\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\Ramstack.FileSystem.Abstractions\Utilities\EnumerableExtensions.cs">
<Link>Utilities\EnumerableExtensions.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.FileSystem.Globbing/GlobbingFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ internal bool IsFileIncluded(string path) =>
/// otherwise, <see langword="false" />.
/// </returns>
internal bool IsDirectoryIncluded(string path) =>
path == "/" || !PathHelper.IsMatch(path, _excludes) && PathHelper.IsPartialMatch(path, _patterns);
path == "/" || (!PathHelper.IsMatch(path, _excludes) && PathHelper.IsPartialMatch(path, _patterns));
}
2 changes: 1 addition & 1 deletion src/Ramstack.FileSystem.Globbing/Internal/PathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static ReadOnlySpan<char> GetPartialPattern(string pattern, int depth)
static bool IsGlobStar(ref char s, int index, int final) =>
index + 2 == final && Unsafe.ReadUnaligned<int>(
ref Unsafe.As<char, byte>(
ref Unsafe.Add(ref s, (nint)(uint)index))) == ('*' << 16 | '*');
ref Unsafe.Add(ref s, (nint)(uint)index))) == (('*' << 16) | '*');
}

#region Vector helper methods
Expand Down
16 changes: 4 additions & 12 deletions src/Ramstack.FileSystem.Physical/PhysicalFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override ValueTask<Stream> OpenReadCoreAsync(CancellationToken cancell
{
// SequentialScan is a performance hint that requires extra sys-call on non-Windows systems.
// https://github.com/dotnet/runtime/blob/46c9a4fff83f35ec659e6659050440aadccf3201/src/libraries/System.Private.CoreLib/src/System/IO/File.cs#L694
var options = Path.DirectorySeparatorChar == '\\'
var options = OperatingSystem.IsWindows()
? FileOptions.Asynchronous | FileOptions.SequentialScan
: FileOptions.Asynchronous;

Expand All @@ -59,11 +59,7 @@ protected override ValueTask<Stream> OpenWriteCoreAsync(CancellationToken cancel
{
EnsureDirectoryExists();

var options = Path.DirectorySeparatorChar == '\\'
? FileOptions.Asynchronous | FileOptions.SequentialScan
: FileOptions.Asynchronous;

var stream = new FileStream(_physicalPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, DefaultBufferSize, options);
var stream = new FileStream(_physicalPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, DefaultBufferSize, FileOptions.Asynchronous);

// Since FileMode.OpenOrCreate doesn't truncate the file, we manually
// set the file length to zero to remove any leftover data.
Expand All @@ -79,16 +75,12 @@ protected override async ValueTask WriteCoreAsync(Stream stream, bool overwrite,

try
{
var options = Path.DirectorySeparatorChar == '\\'
? FileOptions.Asynchronous | FileOptions.SequentialScan
: FileOptions.Asynchronous;

// To overwrite the file, we use FileMode.OpenOrCreate instead of FileMode.Create.
// This avoids a System.UnauthorizedAccessException: Access to the path is denied,
// which can occur if the file has the FileAttributes.Hidden attribute.
var fileMode = overwrite ? FileMode.OpenOrCreate : FileMode.CreateNew;

await using var fs = new FileStream(_physicalPath, fileMode, FileAccess.Write, FileShare.None, DefaultBufferSize, options);
await using var fs = new FileStream(_physicalPath, fileMode, FileAccess.Write, FileShare.None, DefaultBufferSize, FileOptions.Asynchronous);

// Since FileMode.OpenOrCreate doesn't truncate the file, we manually
// set the file length to zero to remove any leftover data.
Expand All @@ -108,7 +100,7 @@ protected override async ValueTask WriteCoreAsync(Stream stream, bool overwrite,
const int WIN32_ERROR_FILE_EXISTS = unchecked((int)0x80070050);
const int POSIX_EEXIST = 17;

var exists = Path.DirectorySeparatorChar == '\\'
var exists = OperatingSystem.IsWindows()
? exception.HResult == WIN32_ERROR_FILE_EXISTS
: exception.HResult == POSIX_EEXIST;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<Compile Include="..\Ramstack.FileSystem.Abstractions\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\Ramstack.FileSystem.Abstractions\Utilities\EnumerableExtensions.cs">
<Link>Utilities\EnumerableExtensions.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<Compile Include="..\Ramstack.FileSystem.Abstractions\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\Ramstack.FileSystem.Abstractions\Utilities\EnumerableExtensions.cs">
<Link>Utilities\EnumerableExtensions.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
Loading