From 471004176cac91622cd5deaeb4f38f18d880da55 Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Thu, 26 Sep 2024 20:58:11 -0500 Subject: [PATCH] Fixed a bug where the concurrent tests were failing due to directories were created concurrently on ensure directory. --- .../Storage/SshNetFileStorage.cs | 12 ++++++++++-- .../Storage/RootedSshNetStorageTests.cs | 2 +- .../Storage/SshNetStorageTests.cs | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs b/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs index ca3117d..f4158be 100644 --- a/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs +++ b/src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs @@ -263,7 +263,7 @@ private void CreateDirectory(string path) string directory = NormalizePath(Path.GetDirectoryName(path)); _logger.LogTrace("Ensuring {Directory} directory exists", directory); - string[] folderSegments = directory?.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty(); + string[] folderSegments = directory?.Split(['/'], StringSplitOptions.RemoveEmptyEntries) ?? []; string currentDirectory = String.Empty; foreach (string segment in folderSegments) @@ -277,7 +277,15 @@ private void CreateDirectory(string path) continue; _logger.LogInformation("Creating {Directory} directory", directory); - _client.CreateDirectory(currentDirectory); + + try + { + _client.CreateDirectory(currentDirectory); + } + catch (Exception ex) when (_client.Exists(currentDirectory)) + { + _logger.LogTrace(ex, "Error creating {Directory} directory: Already exists", directory); + } } } diff --git a/tests/Foundatio.Storage.SshNet.Tests/Storage/RootedSshNetStorageTests.cs b/tests/Foundatio.Storage.SshNet.Tests/Storage/RootedSshNetStorageTests.cs index 8350ec9..6f72900 100644 --- a/tests/Foundatio.Storage.SshNet.Tests/Storage/RootedSshNetStorageTests.cs +++ b/tests/Foundatio.Storage.SshNet.Tests/Storage/RootedSshNetStorageTests.cs @@ -76,7 +76,7 @@ public override Task CanRenameFilesAsync() return base.CanRenameFilesAsync(); } - [Fact(Skip = "Doesn't work well with SFTP")] + [Fact] public override Task CanConcurrentlyManageFilesAsync() { return base.CanConcurrentlyManageFilesAsync(); diff --git a/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs b/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs index 357bdbf..d2918be 100644 --- a/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs +++ b/tests/Foundatio.Storage.SshNet.Tests/Storage/SshNetStorageTests.cs @@ -76,7 +76,7 @@ public override Task CanRenameFilesAsync() return base.CanRenameFilesAsync(); } - [Fact(Skip = "Doesn't work well with SFTP")] + [Fact] public override Task CanConcurrentlyManageFilesAsync() { return base.CanConcurrentlyManageFilesAsync();