diff --git a/source/dub/dub.d b/source/dub/dub.d index 423de81..e75b008 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -825,7 +825,7 @@ } // always upgrade branch based versions - TODO: actually check if there is a new commit available - Package existing = m_packageManager.getPackage(packageId, ver, placement); + Package existing = m_packageManager.getPackage(packageId, ver, location); if (options & FetchOptions.printOnly) { if (existing && existing.version_ != ver) logInfo("A new version for %s is available (%s -> %s). Run \"%s\" to switch.", @@ -863,7 +863,7 @@ if (dstpath.existsFile()) { m_packageManager.refresh(false); - return m_packageManager.getPackage(packageId, ver, dstpath); + return m_packageManager.getPackage(packageId, ver, location); } // repeat download on corrupted zips, see #1336 diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 270ca4a..4ca3b3b 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -195,6 +195,7 @@ } /// ditto + deprecated("Use the overload that takes a `PlacementLocation`") Package getPackage(string name, Version ver, NativePath path) { foreach (p; getPackageIterator(name)) { @@ -205,6 +206,15 @@ return null; } + /// Ditto + Package getPackage(string name, Version ver, PlacementLocation loc) + { + // Bare mode + if (loc >= this.m_repositories.length) + return null; + return this.m_repositories[loc].lookup(name, ver); + } + /// ditto deprecated("Use the overload that accepts a `Version` as second argument") Package getPackage(string name, string ver, NativePath path) @@ -1176,6 +1186,30 @@ } /** + * Looks up already-loaded packages at a specific version + * + * Looks up a package according to this `Location`'s priority, + * that is, packages from the search path and local packages + * have the highest priority. + * + * Params: + * name = The full name of the package to look up + * ver = The version to look up + * + * Returns: + * A `Package` if one was found, `null` if none exists. + */ + private inout(Package) lookup(string name, Version ver) inout { + foreach (pkg; this.localPackages) + if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.strict)) + return pkg; + foreach (pkg; this.fromPath) + if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.strict)) + return pkg; + return null; + } + + /** * Get the final destination a specific package needs to be stored in. * * Note that there needs to be an extra level for libraries like `ae`