diff --git a/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs b/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs index ed57382c..c8fe6d54 100644 --- a/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs +++ b/uSync.BackOffice/SyncHandlers/SyncHandlerBase.cs @@ -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); + } /// diff --git a/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs b/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs index ac67f358..6a9ec250 100644 --- a/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs +++ b/uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs @@ -813,7 +813,7 @@ protected IList 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); } @@ -1022,6 +1022,14 @@ public IEnumerable 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(); @@ -1172,7 +1180,7 @@ protected virtual bool HasChildren(TObject item) /// protected void CreateCleanFile(Guid key, string filename) { - if (string.IsNullOrWhiteSpace(filename) || key == Guid.Empty) + if (string.IsNullOrWhiteSpace(filename)) return; var folder = Path.GetDirectoryName(filename);