Skip to content

Commit

Permalink
fix #605 - check delete by serializing item one last time. (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump authored Apr 15, 2024
1 parent cd9d73e commit c4016f9
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,8 @@ protected virtual void ExportDeletedItem(TObject item, string[] folders, Handler
// don't do anything this thing exists at a higher level. !
return;
}


if (ShouldExportDeletedFile(item, config) is false) return;

var attempt = serializer.SerializeEmpty(item, SyncActionType.Delete, string.Empty);
if (ShouldExport(attempt.Item, config))
Expand All @@ -1634,10 +1635,24 @@ protected virtual void ExportDeletedItem(TObject item, string[] folders, Handler
}
}

/// <summary>
/// get all the possible folders for this handlers
/// </summary>
protected string[] GetDefaultHandlerFolders()
private bool ShouldExportDeletedFile(TObject item, HandlerSettings config)
{
try
{
var deletingAttempt = serializer.Serialize(item, new SyncSerializerOptions(config.Settings));
return ShouldExport(deletingAttempt.Item, config);
}
catch (Exception ex)
{
logger.LogWarning(ex, "Failed to calculate if this item should be exported when deleted, the common option is yes, so we will");
return true;
}
}

/// <summary>
/// get all the possible folders for this handlers
/// </summary>
protected string[] GetDefaultHandlerFolders()
=> rootFolders.Select(f => Path.Combine(f, DefaultFolder)).ToArray();


Expand Down

0 comments on commit c4016f9

Please sign in to comment.