@@ -9,6 +9,32 @@ namespace NServiceBus
9
9
10
10
class FileShareDataBusImplementation : IDataBus
11
11
{
12
+ // to account for mixed platforms ie windows -> linux or linux -> windows
13
+ internal class PathNormalizer
14
+ {
15
+ // Example keys
16
+ // string key1 = "foldername/filename";
17
+ // string key2 = "foldername\\filename";
18
+
19
+ // Normalize the keys
20
+ // string normalizedKey1 = NormalizePath(key1);
21
+ // string normalizedKey2 = NormalizePath(key2);
22
+
23
+ // Output the normalized keys
24
+ // Console.WriteLine(normalizedKey1); // Output will be "foldername\filename" on Windows, "foldername/filename" on Unix-based systems
25
+ // Console.WriteLine(normalizedKey2); // Output will be "foldername\filename" on Windows, "foldername/filename" on Unix-based systems
26
+ internal static string NormalizePath ( string key )
27
+ {
28
+ // Determine the directory separator for the current platform
29
+ char separator = Path . DirectorySeparatorChar ;
30
+ // Replace any forward slashes (common in URIs) and backward slashes with the platform-specific separator
31
+ string normalizedPath = key . Replace ( '/' , separator ) . Replace ( '\\ ' , separator ) ;
32
+
33
+ return normalizedPath ;
34
+ }
35
+ }
36
+
37
+
12
38
public FileShareDataBusImplementation ( string basePath )
13
39
{
14
40
this . basePath = basePath ;
@@ -18,7 +44,7 @@ public FileShareDataBusImplementation(string basePath)
18
44
19
45
public Task < Stream > Get ( string key , CancellationToken cancellationToken = default )
20
46
{
21
- var filePath = Path . Combine ( basePath , key ) ;
47
+ var filePath = Path . Combine ( basePath , PathNormalizer . NormalizePath ( key ) ) ;
22
48
23
49
logger . DebugFormat ( "Opening stream from '{0}'." , filePath ) ;
24
50
0 commit comments