예제 #1
0
 /// <summary>
 /// Enumerates all files and folders in the shadow copy
 /// </summary>
 /// <param name="sources">Source paths to enumerate</param>
 /// <param name="callback">The callback to invoke with each found path</param>
 /// <param name="errorCallback">The callback used to report errors</param>
 public IEnumerable <string> EnumerateFilesAndFolders(IEnumerable <string> sources, Utility.Utility.EnumerationFilterDelegate callback, Utility.Utility.ReportAccessError errorCallback)
 {
     return(sources.SelectMany(s => Utility.Utility.EnumerateFileSystemEntries(s, callback, ListFolders, ListFiles, GetAttributes, errorCallback)));
 }
예제 #2
0
        /// <summary>
        /// Enumerates all files and folders in the shadow copy
        /// </summary>
        /// <param name="sources">Source paths to enumerate</param>
        /// <param name="callback">The callback to invoke with each found path</param>
        /// <param name="errorCallback">The callback used to report errors</param>
        public IEnumerable <string> EnumerateFilesAndFolders(IEnumerable <string> sources, Utility.Utility.EnumerationFilterDelegate callback, Utility.Utility.ReportAccessError errorCallback)
        {
            // Add trailing slashes to folders
            var sanitizedSources = sources.Select(x => DirectoryExists(x) ? Utility.Utility.AppendDirSeparator(x) : x).ToList();

            return(sanitizedSources.SelectMany(
                       s => Utility.Utility.EnumerateFileSystemEntries(s, callback, ListFolders, ListFiles, GetAttributes, errorCallback)
                       ));
        }
예제 #3
0
 /// <summary>
 /// Enumerates all files and folders in the snapshot, restricted to sources
 /// </summary>
 /// <param name="sources">Sources to enumerate</param>
 /// <param name="callback">The callback to invoke with each found path</param>
 /// <param name="errorCallback">The callback used to report errors</param>
 public override IEnumerable <string> EnumerateFilesAndFolders(IEnumerable <string> sources, Utility.Utility.EnumerationFilterDelegate callback, Utility.Utility.ReportAccessError errorCallback)
 {
     // For Windows, ensure we don't store paths with UNC prefix
     return(base.EnumerateFilesAndFolders(sources.Select(SystemIOWindows.StripUNCPrefix), callback, errorCallback));
 }
예제 #4
0
        /// <summary>
        /// Filter supplied <c>folders</c>, removing any folder which itself, or one
        /// of its ancestors, is excluded by the <c>filter</c>.
        /// </summary>
        /// <param name="folders">Folder to filter</param>
        /// <param name="filter">Exclusion filter</param>
        /// <param name="cache">Cache of excluded folders (optional)</param>
        /// <param name="errorCallback"></param>
        /// <returns>Filtered folders</returns>
        private IEnumerable <string> FilterExcludedFolders(IEnumerable <string> folders,
                                                           Utility.Utility.EnumerationFilterDelegate filter, IDictionary <string, bool> cache, Utility.Utility.ReportAccessError errorCallback = null)
        {
            var result = new List <string>();

            foreach (var folder in folders)
            {
                if (m_token.IsCancellationRequested)
                {
                    break;
                }

                try
                {
                    if (!IsFolderOrAncestorsExcluded(folder, filter, cache))
                    {
                        result.Add(folder);
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    errorCallback?.Invoke(folder, folder, ex);
                    filter(folder, folder, FileAttributes.Directory | Utility.Utility.ATTRIBUTE_ERROR);
                }
            }

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Filter supplied <c>files</c>, removing any files which itself, or one
        /// of its parent folders, is excluded by the <c>filter</c>.
        /// </summary>
        /// <param name="files">Files to filter</param>
        /// <param name="filter">Exclusion filter</param>
        /// <param name="cache">Cache of included and excluded files / folders</param>
        /// <param name="errorCallback"></param>
        /// <returns>Filtered files</returns>
        private IEnumerable <string> FilterExcludedFiles(IEnumerable <string> files,
                                                         Utility.Utility.EnumerationFilterDelegate filter, IDictionary <string, bool> cache, Utility.Utility.ReportAccessError errorCallback = null)
        {
            var result = new List <string>();

            foreach (var file in files)
            {
                if (m_token.IsCancellationRequested)
                {
                    break;
                }

                var attr = m_snapshot.FileExists(file) ? m_snapshot.GetAttributes(file) : FileAttributes.Normal;
                try
                {
                    if (!filter(file, file, attr))
                    {
                        continue;
                    }

                    if (!IsFolderOrAncestorsExcluded(Utility.Utility.GetParent(file, true), filter, cache))
                    {
                        result.Add(file);
                    }
                }
                catch (System.Threading.ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    errorCallback?.Invoke(file, file, ex);
                    filter(file, file, attr | Utility.Utility.ATTRIBUTE_ERROR);
                }
            }

            return(result);
        }
예제 #6
0
 /// <summary>
 /// Enumerates all files and folders in the snapshot, restricted to sources
 /// </summary>
 /// <param name="sources">Sources to enumerate</param>
 /// <param name="callback">The callback to invoke with each found path</param>
 /// <param name="errorCallback">The callback used to report errors</param>
 public override IEnumerable <string> EnumerateFilesAndFolders(IEnumerable <string> sources, Utility.Utility.EnumerationFilterDelegate callback, Utility.Utility.ReportAccessError errorCallback)
 {
     // For Windows, ensure we don't store paths with extended device path prefixes (i.e., @"\\?\" or @"\\?\UNC\")
     return(base.EnumerateFilesAndFolders(sources.Select(SystemIOWindows.RemoveExtendedDevicePathPrefix), callback, errorCallback));
 }