Skip to content

Commit a14a078

Browse files
authored
Merge pull request #46 from rameel/cleanup
Clean up, formatting, and maintenance
2 parents 4990a1e + 4f7745d commit a14a078

File tree

9 files changed

+17
-18
lines changed

9 files changed

+17
-18
lines changed

src/Ramstack.FileSystem.Abstractions/Utilities/EnumerableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace Ramstack.FileSystem.Utilities;
33
/// <summary>
44
/// Provides extension methods for the <see cref="IEnumerable{T}"/>.
55
/// </summary>
6-
public static class EnumerableExtensions
6+
internal static class EnumerableExtensions
77
{
88
/// <summary>
99
/// Converts an enumerable sequence to an async-enumerable sequence.

src/Ramstack.FileSystem.Abstractions/Utilities/PathTokenizer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Runtime.CompilerServices;
2-
31
namespace Ramstack.FileSystem.Utilities;
42

53
/// <summary>

src/Ramstack.FileSystem.Abstractions/VirtualPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static bool IsNormalized(ReadOnlySpan<char> path)
173173
for (var j = 1; (uint)j < (uint)path.Length; j++)
174174
{
175175
var ch = path[j];
176-
if (ch == '\\' || ch == '/' && prior == '/')
176+
if (ch == '\\' || (ch == '/' && prior == '/'))
177177
return false;
178178

179179
if (ch == '.' && prior == '/')

src/Ramstack.FileSystem.Adapters/Ramstack.FileSystem.Adapters.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<Compile Include="..\Ramstack.FileSystem.Abstractions\Properties\AssemblyInfo.cs">
3939
<Link>Properties\AssemblyInfo.cs</Link>
4040
</Compile>
41+
<Compile Include="..\Ramstack.FileSystem.Abstractions\Utilities\EnumerableExtensions.cs">
42+
<Link>Utilities\EnumerableExtensions.cs</Link>
43+
</Compile>
4144
</ItemGroup>
4245

4346
<ItemGroup>

src/Ramstack.FileSystem.Globbing/GlobbingFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,5 @@ internal bool IsFileIncluded(string path) =>
103103
/// otherwise, <see langword="false" />.
104104
/// </returns>
105105
internal bool IsDirectoryIncluded(string path) =>
106-
path == "/" || !PathHelper.IsMatch(path, _excludes) && PathHelper.IsPartialMatch(path, _patterns);
106+
path == "/" || (!PathHelper.IsMatch(path, _excludes) && PathHelper.IsPartialMatch(path, _patterns));
107107
}

src/Ramstack.FileSystem.Globbing/Internal/PathHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static ReadOnlySpan<char> GetPartialPattern(string pattern, int depth)
118118
static bool IsGlobStar(ref char s, int index, int final) =>
119119
index + 2 == final && Unsafe.ReadUnaligned<int>(
120120
ref Unsafe.As<char, byte>(
121-
ref Unsafe.Add(ref s, (nint)(uint)index))) == ('*' << 16 | '*');
121+
ref Unsafe.Add(ref s, (nint)(uint)index))) == (('*' << 16) | '*');
122122
}
123123

124124
#region Vector helper methods

src/Ramstack.FileSystem.Physical/PhysicalFile.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected override ValueTask<Stream> OpenReadCoreAsync(CancellationToken cancell
4545
{
4646
// SequentialScan is a performance hint that requires extra sys-call on non-Windows systems.
4747
// https://github.com/dotnet/runtime/blob/46c9a4fff83f35ec659e6659050440aadccf3201/src/libraries/System.Private.CoreLib/src/System/IO/File.cs#L694
48-
var options = Path.DirectorySeparatorChar == '\\'
48+
var options = OperatingSystem.IsWindows()
4949
? FileOptions.Asynchronous | FileOptions.SequentialScan
5050
: FileOptions.Asynchronous;
5151

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

62-
var options = Path.DirectorySeparatorChar == '\\'
63-
? FileOptions.Asynchronous | FileOptions.SequentialScan
64-
: FileOptions.Asynchronous;
65-
66-
var stream = new FileStream(_physicalPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, DefaultBufferSize, options);
62+
var stream = new FileStream(_physicalPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, DefaultBufferSize, FileOptions.Asynchronous);
6763

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

8076
try
8177
{
82-
var options = Path.DirectorySeparatorChar == '\\'
83-
? FileOptions.Asynchronous | FileOptions.SequentialScan
84-
: FileOptions.Asynchronous;
85-
8678
// To overwrite the file, we use FileMode.OpenOrCreate instead of FileMode.Create.
8779
// This avoids a System.UnauthorizedAccessException: Access to the path is denied,
8880
// which can occur if the file has the FileAttributes.Hidden attribute.
8981
var fileMode = overwrite ? FileMode.OpenOrCreate : FileMode.CreateNew;
9082

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

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

111-
var exists = Path.DirectorySeparatorChar == '\\'
103+
var exists = OperatingSystem.IsWindows()
112104
? exception.HResult == WIN32_ERROR_FILE_EXISTS
113105
: exception.HResult == POSIX_EEXIST;
114106

src/Ramstack.FileSystem.Physical/Ramstack.FileSystem.Physical.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<Compile Include="..\Ramstack.FileSystem.Abstractions\Properties\AssemblyInfo.cs">
3939
<Link>Properties\AssemblyInfo.cs</Link>
4040
</Compile>
41+
<Compile Include="..\Ramstack.FileSystem.Abstractions\Utilities\EnumerableExtensions.cs">
42+
<Link>Utilities\EnumerableExtensions.cs</Link>
43+
</Compile>
4144
</ItemGroup>
4245

4346
<ItemGroup>

src/Ramstack.FileSystem.Prefixed/Ramstack.FileSystem.Prefixed.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<Compile Include="..\Ramstack.FileSystem.Abstractions\Properties\AssemblyInfo.cs">
3939
<Link>Properties\AssemblyInfo.cs</Link>
4040
</Compile>
41+
<Compile Include="..\Ramstack.FileSystem.Abstractions\Utilities\EnumerableExtensions.cs">
42+
<Link>Utilities\EnumerableExtensions.cs</Link>
43+
</Compile>
4144
</ItemGroup>
4245

4346
<ItemGroup>

0 commit comments

Comments
 (0)