예제 #1
0
        /// <summary>
        /// Gets all package distributions referenced by the given atom.
        /// </summary>
        /// <param name="atom">the package atom to lookup</param>
        /// <returns>the matching distributions</returns>
        public virtual IDistribution[] LookupAll(Atom atom)
        {
            IPackage pkg = this.ResolvePackage(atom);
            List<IDistribution> results = new List<IDistribution>();

            if (pkg == null)
                throw new PackageNotFoundException(atom.PackageName);

            if (atom.HasVersion || atom.Slot > 0) {        /* find a specific version */
                IDistribution[] matcharr = pkg.Distributions
                    .Where(i => atom.Match(i.Atom))
                    .OrderBy(i => i.Version)
                    .ToArray();
                if (matcharr.Length == 0)
                    throw new DistributionNotFoundException(atom);

                if (atom.Comparison == "=")
                    results.Add(matcharr.SingleOrDefault());
                else {
                    IDistribution[] unmasked = matcharr
                        .Where(i => !i.PortsTree.IsMasked(i))
                        .ToArray();
                    results.AddRange(unmasked.Length > 0 ? unmasked : matcharr);
                }
            } else {                        /* find the best version */
                if (pkg.LatestUnmasked != null)
                    results.Add(pkg.LatestUnmasked);
                else if (pkg.LatestAvailable != null)
                    results.Add(pkg.LatestAvailable);
            }

            if (results.Count == 0)
                throw new DistributionNotFoundException(atom);

            return results.ToArray();
        }
예제 #2
0
        /// <summary>
        /// Determines if the given distribution satisfies dependency requirements for
        /// the current graph.
        /// </summary>
        /// <param name="dist">distribution atom to check</param>
        /// <returns>true if satisfies, false otherwise</returns>
        public bool CheckSatisfies(Atom atom)
        {
            if (!_depmap.ContainsKey(atom.PackageName))
                throw new KeyNotFoundException("Package '" + atom.PackageName + "' is not a dependency.");

            /* the given dist satisfies the requirement if it appears in all matches found */
            foreach (Dependency d in _depmap[atom.PackageName]) {
                if (d.Matches.Where(i => atom.Match(d.Atom)).Count() == 0)
                    return false;
            }

            return true;
        }