Skip to content

Commit

Permalink
Had to do an exists check so rename doesn't error when file exists as…
Browse files Browse the repository at this point in the history
… it's no longer a sync posix rename operation
  • Loading branch information
niemyjski committed Oct 11, 2023
1 parent 91f69ff commit 791dea0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Foundatio.Storage.SshNet/Storage/SshNetFileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ public async Task<bool> RenameFileAsync(string path, string newPath, Cancellatio
_logger.LogInformation("Renaming {Path} to {NewPath}", normalizedPath, normalizedNewPath);
EnsureClientConnected();

if (await ExistsAsync(normalizedNewPath).AnyContext()) {
_logger.LogDebug("Removing existing {NewPath} path for rename operation", normalizedNewPath);
await DeleteFileAsync(normalizedNewPath, cancellationToken).AnyContext();
_logger.LogDebug("Removed existing {NewPath} path for rename operation", normalizedNewPath);
}

try {
await _client.RenameFileAsync(normalizedPath, normalizedNewPath, cancellationToken).AnyContext();
} catch (SftpPathNotFoundException ex) {
Expand Down

0 comments on commit 791dea0

Please sign in to comment.