Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages cannot be sent from Windows to Linux using the file share data bus #7044

Merged
merged 2 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions 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 Expand Up @@ -71,4 +97,4 @@ string GenerateKey(TimeSpan timeToBeReceived)

readonly string basePath;
static readonly ILog logger = LogManager.GetLogger<FileShareDataBusImplementation>();
}
}