Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check if the Package is managed by the Location in lookup #2779

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions source/dub/packagemanager.d
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class PackageManager {
if (!this.m_initialized)
this.refresh();

if (auto pkg = this.m_internal.lookup(name, vers, this))
if (auto pkg = this.m_internal.lookup(name, vers))
return pkg;

foreach (ref location; this.m_repositories)
Expand Down Expand Up @@ -553,11 +553,9 @@ class PackageManager {
*/
bool isManagedPath(NativePath path)
const {
foreach (rep; m_repositories) {
NativePath rpath = rep.packagePath;
if (path.startsWith(rpath))
foreach (rep; m_repositories)
if (rep.isManaged(path))
return true;
}
return false;
}

Expand Down Expand Up @@ -1407,12 +1405,13 @@ package struct Location {
* Returns:
* A `Package` if one was found, `null` if none exists.
*/
inout(Package) lookup(string name, Version ver, PackageManager mgr) inout {
inout(Package) lookup(string name, Version ver) inout {
foreach (pkg; this.localPackages)
if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.standard))
return pkg;
foreach (pkg; this.fromPath) {
auto pvm = mgr.isManagedPackage(pkg) ? VersionMatchMode.strict : VersionMatchMode.standard;
auto pvm = this.isManaged(pkg.basePackage.path) ?
VersionMatchMode.strict : VersionMatchMode.standard;
if (pkg.name == name && pkg.version_.matches(ver, pvm))
return pkg;
}
Expand All @@ -1436,7 +1435,7 @@ package struct Location {
*/
Package load (string name, Version vers, PackageManager mgr)
{
if (auto pkg = this.lookup(name, vers, mgr))
if (auto pkg = this.lookup(name, vers))
return pkg;

string versStr = vers.toString();
Expand Down Expand Up @@ -1472,6 +1471,11 @@ package struct Location {
result.endsWithSlash = true;
return result;
}

/// Determines if a specific path is within a DUB managed Location.
bool isManaged(NativePath path) const {
return path.startsWith(this.packagePath);
}
}

private immutable string OverrideDepMsg =
Expand Down
Loading