src/Microsoft.PackageManagement.NuGetProvider/NugetLightClient.cs
/// <summary>
/// Do a dfs visit. returns false if a cycle is encountered. Add the packageItem to the list at the end of each visit
/// </summary>
/// <param name="packageItem"></param>
/// <param name="dependencyToBeInstalled"></param>
/// <param name="permanentlyMarked"></param>
/// <param name="temporarilyMarked"></param>
/// <param name="processedDependencies"></param>
/// <param name="request"></param>
/// <returns></returns>
Do a dfs visit. returns false if a cycle is encountered. Add the packageItem to the list at the end of each visit
Do a dfs visit . returns false if a cycle is encountered . Add the packageItem to the list at the end of each visit
internal static bool DepthFirstVisit(PackageItem packageItem, HashSet<PackageItem> temporarilyMarked, HashSet<PackageItem> permanentlyMarked, List<PackageItem> dependencyToBeInstalled, HashSet<string> processedDependencies, NuGetRequest request)
        {
            if (temporarilyMarked.Contains(packageItem))
            {
                return false;
            }
            if (permanentlyMarked.Contains(packageItem))
            {
                return true;
            }
            temporarilyMarked.Add(packageItem);
            foreach (var dependency in GetPackageDependenciesHelper(packageItem, processedDependencies, request))
            {
                if (!DepthFirstVisit(dependency, temporarilyMarked, permanentlyMarked, dependencyToBeInstalled, processedDependencies, request))
                {
                    return false;
                }
            }
            dependencyToBeInstalled.Add(packageItem);
            permanentlyMarked.Add(packageItem);
            temporarilyMarked.Remove(packageItem);
            return true;
        }
internal static bool DepthFirstVisit ( PackageItem packageItem , HashSet < PackageItem > temporarilyMarked , HashSet < PackageItem > permanentlyMarked , List < PackageItem > dependencyToBeInstalled , HashSet < string > processedDependencies , NuGetRequest request ) { if ( temporarilyMarked . Contains ( packageItem ) ) { return false ; } if ( permanentlyMarked . Contains ( packageItem ) ) { return true ; } temporarilyMarked . Add ( packageItem ) ; foreach ( var dependency in GetPackageDependenciesHelper ( packageItem , processedDependencies , request ) ) { if ( ! DepthFirstVisit ( dependency , temporarilyMarked , permanentlyMarked , dependencyToBeInstalled , processedDependencies , request ) ) { return false ; } } dependencyToBeInstalled . Add ( packageItem ) ; permanentlyMarked . Add ( packageItem ) ; temporarilyMarked . Remove ( packageItem ) ; return true ; }
Do a dfs visit.
Do a dfs visit .
// dependency loop detected because the element is temporarily marked // this is permanently marked. So we don't have to visit it. // This is to resolve a case where we have: A->B->C and A->C. Then we need this when we visit C again from either B or A. // Mark this node temporarily so we can detect cycle. // Visit the dependency // if dfs returns false then we have encountered a loop // otherwise visit the next dependency // Add the package to the list so we can install later // Done with this node so mark it permanently // Unmark it temporarily
None
packageItem
PackageItem
None
temporarilyMarked
HashSet<PackageItem>
None
permanentlyMarked
HashSet<PackageItem>
None
dependencyToBeInstalled
List<PackageItem>
None
processedDependencies
HashSet<string>
None
request
NuGetRequest
None