Exemple #1
0
        /// <summary>
        /// Tests if specified folder, or any of its ancestors, is excluded by the filter
        /// </summary>
        /// <param name="folder">Folder to test</param>
        /// <param name="filter">Filter</param>
        /// <param name="cache">Cache of excluded folders (optional)</param>
        /// <returns>True if excluded, false otherwise</returns>
        private bool IsFolderOrAncestorsExcluded(string folder, Utility.Utility.EnumerationFilterDelegate filter, IDictionary <string, bool> cache)
        {
            List <string> parents = null;

            while (folder != null)
            {
                if (m_token.IsCancellationRequested)
                {
                    break;
                }

                // first check cache
                if (cache.TryGetValue(folder, out var include))
                {
                    if (include)
                    {
                        return(false);
                    }

                    break; // hit!
                }

                // remember folder for cache
                if (parents == null)
                {
                    parents = new List <string>(); // create on-demand
                }
                parents.Add(folder);


                var attr = m_snapshot.DirectoryExists(folder) ? m_snapshot.GetAttributes(folder) : FileAttributes.Directory;

                if (!filter(folder, folder, attr))
                {
                    break; // excluded
                }
                folder = Utility.Utility.GetParent(folder, true);
            }

            if (folder != null)
            {
                // update cache
                parents?.ForEach(p => cache[p] = false);
            }

            return(folder != null);
        }