public void AddFolderWhereParentIncludedIsTrueAndChildIsNotIncluded()
        {
            SortedFolderEntries sfe              = SetupDefaultEntries();
            LazyUTF8String      name             = ConstructLazyUTF8String("ChildNotIncluded");
            SparseFolderData    sparseFolderData = new SparseFolderData();

            sparseFolderData.Children.Add("Child", new SparseFolderData());
            sfe.GetOrAddFolder(new[] { name }, partIndex: 0, parentIsIncluded: true, rootSparseFolderData: sparseFolderData);
            ValidateFolder(sfe, name, isIncludedValue: false);
        }
        public void AddFolderBelowTopLevelNotIncluded()
        {
            SortedFolderEntries sfe              = SetupDefaultEntries();
            LazyUTF8String      name             = ConstructLazyUTF8String("Child");
            LazyUTF8String      name2            = ConstructLazyUTF8String("GrandChild");
            SparseFolderData    sparseFolderData = new SparseFolderData();

            sparseFolderData.Children.Add("Child", new SparseFolderData());
            sfe.GetOrAddFolder(new[] { name, name2 }, partIndex: 1, parentIsIncluded: true, rootSparseFolderData: sparseFolderData);
            ValidateFolder(sfe, name2, isIncludedValue: false);
        }
            public FolderData GetOrAddFolder(
                LazyUTF8String[] pathParts,
                int partIndex,
                bool parentIsIncluded,
                SparseFolderData rootSparseFolderData)
            {
                int index = this.GetSortedEntriesIndexOfName(pathParts[partIndex]);

                if (index >= 0)
                {
                    return((FolderData)this.sortedEntries[index]);
                }

                bool isIncluded = true;

                if (rootSparseFolderData.Children.Count > 0)
                {
                    if (parentIsIncluded)
                    {
                        // Need to check if this child folder should be included
                        SparseFolderData folderData = rootSparseFolderData;
                        for (int i = 0; i <= partIndex; i++)
                        {
                            if (folderData.IsRecursive)
                            {
                                break;
                            }

                            string childFolderName = pathParts[i].GetString();
                            if (!folderData.Children.ContainsKey(childFolderName))
                            {
                                isIncluded = false;
                                break;
                            }
                            else
                            {
                                folderData = folderData.Children[childFolderName];
                            }
                        }
                    }
                    else
                    {
                        isIncluded = false;
                    }
                }

                return(this.InsertFolder(pathParts[partIndex], ~index, isIncluded: isIncluded));
            }