Skip to content

Commit d676c7c

Browse files
authored
Merge pull request #7045 from Particular/backport-7042-to-8-2
FileShareDataBusImplementation throws a FileNotFoundException when sending databus messages from Windows to Linux
2 parents 888fc13 + 44f7818 commit d676c7c

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
@@ -9,6 +9,32 @@ namespace NServiceBus
99

1010
class FileShareDataBusImplementation : IDataBus
1111
{
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+
1238
public FileShareDataBusImplementation(string basePath)
1339
{
1440
this.basePath = basePath;
@@ -18,7 +44,7 @@ public FileShareDataBusImplementation(string basePath)
1844

1945
public Task<Stream> Get(string key, CancellationToken cancellationToken = default)
2046
{
21-
var filePath = Path.Combine(basePath, key);
47+
var filePath = Path.Combine(basePath, PathNormalizer.NormalizePath(key));
2248

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

0 commit comments

Comments
 (0)