Skip to content

Commit

Permalink
Allow for the creation of clean files at the root level.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Jul 9, 2024
1 parent e06547c commit e6eeb99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ private int GetCleanParentId(string cleanFile)
var node = syncFileService.LoadXElement(cleanFile);
var id = node.Attribute("Id").ValueOrDefault(0);
if (id != 0) return id;
return GetCleanParent(cleanFile)?.Id ?? 0;

return GetCleanParent(cleanFile)?.Id ??
(node.GetKey() == Guid.Empty ? -1 : 0);

}

/// <summary>
Expand Down
12 changes: 10 additions & 2 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ protected IList<Guid> GetFolderKeys(string folder, bool flat)
{
var node = XElement.Load(file);
var key = node.GetKey();
if (key != Guid.Empty && !keys.Contains(key))
if (!keys.Contains(key))
{
keys.Add(key);
}
Expand Down Expand Up @@ -1022,6 +1022,14 @@ public IEnumerable<uSyncAction> Export(Udi udi, string[] folders, HandlerSetting
if (item != null)
return Export(item, folders, settings);

if (udi.IsRoot && settings.CreateClean)
{
// for roots we still can create a clean
var targetFolder = folders.Last();
var filename = Path.Combine(targetFolder, $"{Guid.Empty}.{this.uSyncConfig.Settings.DefaultExtension}");
CreateCleanFile(Guid.Empty, filename);
}

return uSyncAction.Fail(nameof(udi), this.handlerType, this.ItemType, ChangeType.Fail, $"Item not found {udi}",
new KeyNotFoundException(nameof(udi)))
.AsEnumerableOfOne();
Expand Down Expand Up @@ -1172,7 +1180,7 @@ protected virtual bool HasChildren(TObject item)
/// </summary>
protected void CreateCleanFile(Guid key, string filename)
{
if (string.IsNullOrWhiteSpace(filename) || key == Guid.Empty)
if (string.IsNullOrWhiteSpace(filename))
return;

var folder = Path.GetDirectoryName(filename);
Expand Down

0 comments on commit e6eeb99

Please sign in to comment.