Skip to content

Commit

Permalink
Handle Exceptions on Rename/Move
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Mar 20, 2024
1 parent 16a4e65 commit 5de96e0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Shoko.Server/Services/VideoLocal_PlaceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void RenameAndMoveAsRequired(SVR_VideoLocal_Place place)

var retryPolicy = Policy
.HandleResult<IFileOperationResult>(a => a.CanRetry)
.Or<Exception>(e =>
{
_logger.LogError(e, "Error Renaming/Moving File");
return false;
})
.WaitAndRetry(new[]
{
TimeSpan.FromMilliseconds((int)DelayInUse.First),
Expand All @@ -61,12 +66,12 @@ public void RenameAndMoveAsRequired(SVR_VideoLocal_Place place)
var result = retryPolicy.Execute(() => invert ? RenameIfRequired(place) : MoveFileIfRequired(place));

// Don't bother renaming if we couldn't move. It'll need user interaction
if (!result.IsSuccess) return;
if (!result?.IsSuccess ?? true) return;

// Retry logic for the second attempt
result = retryPolicy.Execute(() => invert ? MoveFileIfRequired(place) : RenameIfRequired(place));

if (!result.IsSuccess) return;
if (!result?.IsSuccess ?? true) return;

try
{
Expand Down

0 comments on commit 5de96e0

Please sign in to comment.