Skip to content

Commit

Permalink
Fix: Improve Folder clean reporting and code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Oct 2, 2019
1 parent 431f554 commit 50e4081
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
14 changes: 10 additions & 4 deletions uSync8.BackOffice/SyncHandlers/SyncHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void ProcessSecondPasses(IDictionary<string, TObject> updates, HandlerSe
serializer.Save(updatedItems);
}


}

protected virtual IEnumerable<uSyncAction> ImportFolder(string folder, HandlerSettings config, Dictionary<string, TObject> updates, bool force, SyncUpdateCallback callback)
Expand Down Expand Up @@ -238,6 +238,8 @@ protected virtual IEnumerable<uSyncAction> ImportFolder(string folder, HandlerSe
{
actions.AddRange(CleanFolder(cleanFile, false));
}
// remove the actual cleans (they will have been replaced by the deletes
actions.RemoveAll(x => x.Change == ChangeType.Clean);
}

callback?.Invoke("", 1, 1);
Expand Down Expand Up @@ -297,12 +299,12 @@ protected IEnumerable<uSyncAction> DeleteMissingItems(TObject parent, IEnumerabl
if (!keys.Contains(item.Key))
{
var actualItem = GetFromService(item.Key);
var name = actualItem.Id;
var name = GetItemName(actualItem);

if (!reportOnly)
DeleteViaService(actualItem);

actions.Add(uSyncActionHelper<TObject>.SetAction(SyncAttempt<TObject>.Succeed(name.ToString(), ChangeType.Delete), string.Empty));
actions.Add(uSyncActionHelper<TObject>.SetAction(SyncAttempt<TObject>.Succeed(name, ChangeType.Delete), string.Empty));
}
}

Expand Down Expand Up @@ -514,9 +516,13 @@ private IEnumerable<uSyncAction> ReportElement(XElement node, string filename)
}

action.Message = $"{action.Change.ToString()}";
actions.Add(action);
}
else
{
actions.Add(action);
}

actions.Add(action);
return actions;
}
catch (FormatException fex)
Expand Down
5 changes: 4 additions & 1 deletion uSync8.BackOffice/SyncHandlers/SyncHandlerLevelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ protected override IEnumerable<uSyncAction> ImportFolder(string folder, HandlerS
// then we consider the folder safe to clean
foreach (var cleanfile in cleanMarkers)
{
actions.AddRange(CleanFolder(cleanfile, true));
actions.AddRange(CleanFolder(cleanfile, false));
}
// remove the actual cleans (they will have been replaced by the deletes
actions.RemoveAll(x => x.Change == ChangeType.Clean);

}

callback?.Invoke("", 1, 1);
Expand Down
13 changes: 12 additions & 1 deletion uSync8.ContentEdition/Serializers/ContentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ protected override void SaveItem(IContent item)
}

protected override void DeleteItem(IContent item)
=> contentService.Delete(item);
{
try
{
contentService.Delete(item);
}
catch (ArgumentNullException ex)
{
// we can get thrown a null argument exception by the notifer,
// which is non critical! but we are ignoring this error. ! <= 8.1.5
if (!ex.Message.Contains("siteUri")) throw ex;
}
}
}
}
2 changes: 2 additions & 0 deletions uSync8.Core/Serialization/SyncSerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ protected SyncAttempt<TObject> ProcessAction(XElement node, SerializerFlags flag
case SyncActionType.Rename:
return ProcessRename(key, alias, flags);
case SyncActionType.Clean:
// we return a 'clean' success, but this is then picked up
// in the handler, as something to clean, so the handler does it.
return SyncAttempt<TObject>.Succeed(alias, ChangeType.Clean);
default:
return SyncAttempt<TObject>.Succeed(alias, ChangeType.NoChange);
Expand Down

0 comments on commit 50e4081

Please sign in to comment.