Skip to content

Commit 3247dd5

Browse files
committed
Refactor path normalization to use PathNormalizer
Replaces custom path normalization logic in PetroglyphFileSystem with PathNormalizer from AnakinRaW.CommonUtilities. Moves LinuxDirectorySeparatorNormalizeOptions to a static readonly field. Cleans up unused usings and retains legacy code as comments for reference.
1 parent 13f26c5 commit 3247dd5

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System;
2-
using System.IO;
3-
using System.IO.Abstractions;
4-
using System.Runtime.CompilerServices;
5-
using System.Runtime.InteropServices;
6-
using Microsoft.Extensions.DependencyInjection;
2+
using AnakinRaW.CommonUtilities.FileSystem.Normalization;
73
using PG.StarWarsGame.Engine.Utilities;
84

95
namespace PG.StarWarsGame.Engine.IO;
@@ -15,17 +11,17 @@ internal void NormalizePath(ref ValueStringBuilder stringBuilder)
1511
NormalizePath(stringBuilder.RawChars.Slice(0, stringBuilder.Length));
1612
}
1713

18-
// TODO: Check whether we can eliminate the double slash normalization
19-
// once we migrated to PGFileSystem
2014
private static void NormalizePath(Span<char> path)
2115
{
22-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
23-
return;
24-
for (var i = 0; i < path.Length; i++)
25-
{
26-
var c = path[i];
27-
if (IsDirectorySeparator(c))
28-
path[i] = '/';
29-
}
16+
PathNormalizer.Normalize(path, path, LinuxDirectorySeparatorNormalizeOptions);
17+
18+
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
19+
// return;
20+
//for (var i = 0; i < path.Length; i++)
21+
//{
22+
// var c = path[i];
23+
// if (IsDirectorySeparator(c))
24+
// path[i] = '/';
25+
//}
3026
}
3127
}

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.PathEqual.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ namespace PG.StarWarsGame.Engine.IO;
77

88
public sealed partial class PetroglyphFileSystem
99
{
10-
private static readonly PathNormalizeOptions LinuxDirectorySeparatorNormalizeOptions = new PathNormalizeOptions
11-
{
12-
TreatBackslashAsSeparator = true,
13-
UnifyDirectorySeparators = true
14-
};
1510

1611
public bool PathsAreEqual(string pathA, string pathB)
1712
{

src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/IO/PetroglyphFileSystem.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
using AnakinRaW.CommonUtilities.FileSystem.Normalization;
2+
using Microsoft.Extensions.DependencyInjection;
13
using System;
24
using System.IO;
35
using System.IO.Abstractions;
46
using System.Runtime.CompilerServices;
5-
using Microsoft.Extensions.DependencyInjection;
67

78
namespace PG.StarWarsGame.Engine.IO;
89

@@ -17,6 +18,13 @@ public sealed partial class PetroglyphFileSystem
1718
private const char DirectorySeparatorChar = '/';
1819
private const char AltDirectorySeparatorChar = '\\';
1920

21+
private static readonly PathNormalizeOptions LinuxDirectorySeparatorNormalizeOptions = new()
22+
{
23+
TreatBackslashAsSeparator = true, // Ensure that we treat backslashes as separators on Linux
24+
UnifyDirectorySeparators = true,
25+
UnifySeparatorKind = DirectorySeparatorKind.System
26+
};
27+
2028
private readonly IFileSystem _underlyingFileSystem;
2129

2230
/// <summary>

0 commit comments

Comments
 (0)