Skip to content

Commit 96b60e8

Browse files
authored
Merge pull request #7047 from Particular/backport-7042-to-7-8
FileShareDataBusImplementation throws a FileNotFoundException when sending databus messages from Windows to Linux
2 parents e2a99a3 + 59fe14c commit 96b60e8

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/NServiceBus.Core/DataBus/FileShareDataBusImplementation.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@ namespace NServiceBus
88

99
class FileShareDataBusImplementation : IDataBus
1010
{
11+
// to account for mixed platforms ie windows -> linux or linux -> windows
12+
internal class PathNormalizer
13+
{
14+
// Example keys
15+
// string key1 = "foldername/filename";
16+
// string key2 = "foldername\\filename";
17+
18+
// Normalize the keys
19+
// string normalizedKey1 = NormalizePath(key1);
20+
// string normalizedKey2 = NormalizePath(key2);
21+
22+
// Output the normalized keys
23+
// Console.WriteLine(normalizedKey1); // Output will be "foldername\filename" on Windows, "foldername/filename" on Unix-based systems
24+
// Console.WriteLine(normalizedKey2); // Output will be "foldername\filename" on Windows, "foldername/filename" on Unix-based systems
25+
internal static string NormalizePath(string key)
26+
{
27+
// Determine the directory separator for the current platform
28+
char separator = Path.DirectorySeparatorChar;
29+
// Replace any forward slashes (common in URIs) and backward slashes with the platform-specific separator
30+
string normalizedPath = key.Replace('/', separator).Replace('\\', separator);
31+
32+
return normalizedPath;
33+
}
34+
}
35+
36+
1137
public FileShareDataBusImplementation(string basePath)
1238
{
1339
this.basePath = basePath;
@@ -17,7 +43,7 @@ public FileShareDataBusImplementation(string basePath)
1743

1844
public Task<Stream> Get(string key)
1945
{
20-
var filePath = Path.Combine(basePath, key);
46+
var filePath = Path.Combine(basePath, PathNormalizer.NormalizePath(key));
2147

2248
logger.DebugFormat("Opening stream from '{0}'.", filePath);
2349

0 commit comments

Comments
 (0)