Skip to content

Commit

Permalink
Merge pull request #7046 from Particular/backport-7042-to-8-1
Browse files Browse the repository at this point in the history
FileShareDataBusImplementation throws a FileNotFoundException when sending databus messages from Windows to Linux
  • Loading branch information
jpalac committed May 30, 2024
2 parents e5df331 + 9062003 commit cc154ed
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/NServiceBus.Core/DataBus/FileShareDataBusImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ namespace NServiceBus

class FileShareDataBusImplementation : IDataBus
{
// to account for mixed platforms ie windows -> linux or linux -> windows
internal class PathNormalizer
{
// Example keys
// string key1 = "foldername/filename";
// string key2 = "foldername\\filename";

// Normalize the keys
// string normalizedKey1 = NormalizePath(key1);
// string normalizedKey2 = NormalizePath(key2);

// Output the normalized keys
// Console.WriteLine(normalizedKey1); // Output will be "foldername\filename" on Windows, "foldername/filename" on Unix-based systems
// Console.WriteLine(normalizedKey2); // Output will be "foldername\filename" on Windows, "foldername/filename" on Unix-based systems
internal static string NormalizePath(string key)
{
// Determine the directory separator for the current platform
char separator = Path.DirectorySeparatorChar;
// Replace any forward slashes (common in URIs) and backward slashes with the platform-specific separator
string normalizedPath = key.Replace('/', separator).Replace('\\', separator);

return normalizedPath;
}
}


public FileShareDataBusImplementation(string basePath)
{
this.basePath = basePath;
Expand All @@ -18,7 +44,7 @@ public FileShareDataBusImplementation(string basePath)

public Task<Stream> Get(string key, CancellationToken cancellationToken = default)
{
var filePath = Path.Combine(basePath, key);
var filePath = Path.Combine(basePath, PathNormalizer.NormalizePath(key));

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

Expand Down

0 comments on commit cc154ed

Please sign in to comment.