Skip to content

Commit

Permalink
Fix #635, duplicate deletes still cause error (when duplicate deletes…
Browse files Browse the repository at this point in the history
… are ok).
  • Loading branch information
KevinJump committed May 23, 2024
1 parent a3a58d6 commit fbbe794
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions uSync.BackOffice/Services/SyncFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@
using System.Xml.Linq;
using System.Xml.Serialization;

using MessagePack.Formatters;

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Org.BouncyCastle.Crypto.Engines;

using Umbraco.Cms.Core.Extensions;
using Umbraco.Extensions;

using uSync.BackOffice.Models;
using uSync.Core;
using uSync.Core.Tracking;

namespace uSync.BackOffice.Services
{
/// <summary>
/// putting all file actions in a service,
/// so if we want to abstract later we can.
/// </summary>
public class SyncFileService
/// <summary>
/// putting all file actions in a service,
/// so if we want to abstract later we can.
/// </summary>
public class SyncFileService
{
private readonly ILogger<SyncFileService> logger;
private readonly IHostEnvironment _hostEnvironment;
Expand Down Expand Up @@ -509,36 +503,39 @@ public IEnumerable<OrderedNodeInfo> MergeFolders(string[] folders, string extens
foreach (var item in items)
{
var itemKey = item.Value.Node.GetKey();
if (item.Value.Node.IsEmptyItem() is false || item.Value.Node.GetEmptyAction() == SyncActionType.Delete)
if (item.Value.Node.IsEmptyItem() is false)
{
if (localKeys.Contains(itemKey))
{
throw new Exception($"Duplicate: Item key {itemKey} already exists for {item.Key} - run uSync Health check for more info.");
}

localKeys.Add(itemKey);
}
else

if (elements.TryGetValue(item.Key, out var value))
{
// merge these files.
item.Value.SetNode(MergeNodes(value.Node, item.Value.Node, trackerBase));
item.Value.FileName = $"{uSyncConstants.MergedFolderName}/{Path.GetFileName(item.Value.FileName)}";
}
}
else
{
if (item.Value.Node.GetEmptyAction() == SyncActionType.Clean)
switch (item.Value.Node.GetEmptyAction())
{
// cleans are added, these run a clean up at the end, so if they exist
// we need to add them, but they can clash in terms of keys.
_ = cleanElements.TryAdd(item.Key, item.Value);
case SyncActionType.Delete:
// deletes get added, but there can be duplicate deletes,
// we don't care, we just need one, (so we can add them multiple times).
break;
case SyncActionType.Clean:
// cleans are added, these run a clean up at the end, so if they exist
// we need to add them, but they can clash in terms of keys.
_ = cleanElements.TryAdd(item.Key, item.Value);
continue;
case SyncActionType.Rename: // renames are just markers to make sure they don't leave things on disk.
case SyncActionType.None: // none should never happen, we can ignore them..
default:
continue;
}
else
{
// empty if its anything but a delete we ignore it.
// renames are just markers to make sure they don't leave things on disk.
continue;
}
}

if (elements.TryGetValue(item.Key, out var value))
{
// merge these files.
item.Value.SetNode(MergeNodes(value.Node, item.Value.Node, trackerBase));
item.Value.FileName = $"{uSyncConstants.MergedFolderName}/{Path.GetFileName(item.Value.FileName)}";
}

elements[item.Key] = item.Value;
Expand Down

0 comments on commit fbbe794

Please sign in to comment.