Skip to content

Commit

Permalink
Fixed a bug where the concurrent tests were failing due to directorie…
Browse files Browse the repository at this point in the history
…s were created concurrently on ensure directory.
  • Loading branch information
niemyjski committed Sep 27, 2024
1 parent 75cbdcd commit 4710041
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
string[] folderSegments = directory?.Split(['/'], StringSplitOptions.RemoveEmptyEntries) ?? [];
string currentDirectory = String.Empty;

foreach (string segment in folderSegments)
Expand All @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4710041

Please sign in to comment.