示例#1
0
        /// <summary>
        /// Creates an instance of <see cref="DirectoryScrubber"/>.
        /// </summary>
        /// <remarks>
        /// <paramref name="isPathInBuild"/> is a delegate that returns true if a given path is in the build.
        /// Basically, a path is in a build if it points to an artifact in the pip graph, i.e., path to a source file, or
        /// an output file, or a sealed directory. Paths that are in the build should not be deleted.
        ///
        /// <paramref name="pathsToScrub"/> contains a list of paths, including their child paths, that need to be
        /// scrubbed. Basically, the directory scrubber enumerates those paths recursively for removing extraneous files
        /// or directories in those list.
        ///
        /// <paramref name="blockedPaths"/> stop the above enumeration performed by directory scrubber. All file/directories
        /// underneath a blocked path should not be removed.
        ///
        /// <paramref name="nonDeletableRootDirectories"/> contains list of directory paths that can never be deleted, however,
        /// the contents of the directory can be scrubbed. For example, mount roots should not be deleted.
        /// </remarks>
        public DirectoryScrubber(
            LoggingContext loggingContext,
            ILoggingConfiguration loggingConfiguration,
            Func <string, bool> isPathInBuild,
            IEnumerable <string> pathsToScrub,
            IEnumerable <string> blockedPaths,
            IEnumerable <string> nonDeletableRootDirectories,
            MountPathExpander mountPathExpander,
            int maxDegreeParallelism,
            ITempDirectoryCleaner tempDirectoryCleaner = null)
        {
            m_loggingContext              = loggingContext;
            m_loggingConfiguration        = loggingConfiguration;
            m_isPathInBuild               = isPathInBuild;
            m_pathsToScrub                = CollapsePaths(pathsToScrub).ToList();
            m_blockedPaths                = new HashSet <string>(blockedPaths, StringComparer.OrdinalIgnoreCase);
            m_mountPathExpander           = mountPathExpander;
            m_maxDegreeParallelism        = maxDegreeParallelism;
            m_nonDeletableRootDirectories = new HashSet <string>(nonDeletableRootDirectories, StringComparer.OrdinalIgnoreCase);

            if (mountPathExpander != null)
            {
                m_nonDeletableRootDirectories.UnionWith(mountPathExpander.GetAllRoots().Select(p => p.ToString(mountPathExpander.PathTable)));
            }

            m_tempDirectoryCleaner = tempDirectoryCleaner;
        }
示例#2
0
        /// <nodoc />
        public static Xldb.Proto.MountPathExpander ToMountPathExpander(this MountPathExpander mount, PathTable pathTable, NameExpander nameExpander)
        {
            var xldbMountPathExpander = new Xldb.Proto.MountPathExpander();

            xldbMountPathExpander.WriteableRoots.AddRange(mount.GetWritableRoots().Select(path => path.ToAbsolutePath(pathTable, nameExpander)));
            xldbMountPathExpander.PathsWithAllowedCreateDirectory.AddRange(mount.GetPathsWithAllowedCreateDirectory().Select(path => path.ToAbsolutePath(pathTable, nameExpander)));
            xldbMountPathExpander.ScrubbableRoots.AddRange(mount.GetScrubbableRoots().Select(path => path.ToAbsolutePath(pathTable, nameExpander)));
            xldbMountPathExpander.AllRoots.AddRange(mount.GetAllRoots().Select(path => path.ToAbsolutePath(pathTable, nameExpander)));

            foreach (var kvp in mount.GetAllMountsByName())
            {
                xldbMountPathExpander.MountsByName.Add(kvp.Key, kvp.Value.ToSemanticPathInfo(pathTable, nameExpander));
            }

            return(xldbMountPathExpander);
        }
示例#3
0
        /// <summary>
        /// Scrubs extraneous files and directories.
        /// </summary>
        /// <param name="isPathInBuild">
        /// A function that returns true if a given path is in the build.
        /// Basically, a path is in a build if it points to an artifact in the pip graph, i.e., path to a source file, or
        /// an output file, or a sealed directory. Paths that are in the build should not be deleted.
        /// </param>
        /// <param name="pathsToScrub">
        /// Contains a list of paths, including their child paths, that need to be
        /// scrubbed. Basically, the directory scrubber enumerates those paths recursively for removing extraneous files
        /// or directories in those list.
        /// </param>
        /// <param name="blockedPaths">
        /// Stop the above enumeration performed by directory scrubber. All file/directories underneath a blocked path should not be removed.
        /// </param>
        /// <param name="nonDeletableRootDirectories">
        /// Contains list of directory paths that can never be deleted, however,
        /// the contents of the directory can be scrubbed. For example, mount roots should not be deleted.
        /// </param>
        /// <param name="mountPathExpander">
        /// Optional mount path expander.  When used, its roots are treated as non-deletable.
        /// </param>
        public bool RemoveExtraneousFilesAndDirectories(
            Func <string, bool> isPathInBuild,
            IEnumerable <string> pathsToScrub,
            IEnumerable <string> blockedPaths,
            IEnumerable <string> nonDeletableRootDirectories,
            MountPathExpander mountPathExpander = null)
        {
            var finalPathsToScrub = CollapsePaths(pathsToScrub).ToList();
            var finalBlockedPaths = new HashSet <string>(blockedPaths, StringComparer.OrdinalIgnoreCase);
            var finalNonDeletableRootDirectories = new HashSet <string>(nonDeletableRootDirectories, StringComparer.OrdinalIgnoreCase);

            if (mountPathExpander != null)
            {
                finalNonDeletableRootDirectories.UnionWith(mountPathExpander.GetAllRoots().Select(p => p.ToString(mountPathExpander.PathTable)));
            }

            return(RemoveExtraneousFilesAndDirectories(isPathInBuild, finalPathsToScrub, finalBlockedPaths, finalNonDeletableRootDirectories, mountPathExpander));
        }
示例#4
0
        /// <summary>
        /// Scrubs extraneous files and directories.
        /// </summary>
        /// <param name="isPathInBuild">
        /// A function that returns true if a given path is in the build.
        /// Basically, a path is in a build if it points to an artifact in the pip graph, i.e., path to a source file, or
        /// an output file, or a sealed directory. Paths that are in the build should not be deleted.
        /// </param>
        /// <param name="pathsToScrub">
        /// Contains a list of paths, including their child paths, that need to be
        /// scrubbed. Basically, the directory scrubber enumerates those paths recursively for removing extraneous files
        /// or directories in those list.
        /// </param>
        /// <param name="blockedPaths">
        /// Stop the above enumeration performed by directory scrubber. All file/directories underneath a blocked path should not be removed.
        /// </param>
        /// <param name="statisticIdentifier">
        /// Identifies the purpose of this scrubber invocation in telemetry and logging. Use this to differentiate since there can
        /// be multiple scrubber invocations in the same build session for different purposes.
        /// </param>
        /// <param name="nonDeletableRootDirectories">
        /// Contains list of directory paths that can never be deleted, however,
        /// the contents of the directory can be scrubbed. For example, mount roots should not be deleted.
        /// </param>
        /// <param name="mountPathExpander">
        /// Optional mount path expander.  When used, its roots are treated as non-deletable.
        /// </param>
        /// <param name="logRemovedFiles">
        /// Optional flag for logging removed files.
        /// </param>
        public bool RemoveExtraneousFilesAndDirectories(
            Func <string, bool> isPathInBuild,
            IEnumerable <string> pathsToScrub,
            IEnumerable <string> blockedPaths,
            IEnumerable <string> nonDeletableRootDirectories,
            string statisticIdentifier          = Category,
            MountPathExpander mountPathExpander = null,
            bool logRemovedFiles = true)
        {
            var finalPathsToScrub = CollapsePaths(pathsToScrub).ToList();
            var finalBlockedPaths = new HashSet <string>(blockedPaths, OperatingSystemHelper.PathComparer);
            var finalNonDeletableRootDirectories = new HashSet <string>(nonDeletableRootDirectories, OperatingSystemHelper.PathComparer);

            if (mountPathExpander != null)
            {
                finalNonDeletableRootDirectories.UnionWith(mountPathExpander.GetAllRoots().Select(p => p.ToString(mountPathExpander.PathTable)));
            }

            return(RemoveExtraneousFilesAndDirectories(isPathInBuild, finalPathsToScrub, finalBlockedPaths, finalNonDeletableRootDirectories, mountPathExpander, logRemovedFiles, statisticIdentifier));
        }