Skip to content

Commit 606a429

Browse files
committed
PackMan: Deprecate overload leaking location path
Currently, a lot of the internals of the PackageManager are leaking. The getPackage overload accepting both a version and a NativePath is an example of such a leak, and looking at the usage sites show that things can be simplified by taking a PlacementLocation, which is a higher level representation of the path.
1 parent 963486c commit 606a429

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

source/dub/dub.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ class Dub {
825825
}
826826

827827
// always upgrade branch based versions - TODO: actually check if there is a new commit available
828-
Package existing = m_packageManager.getPackage(packageId, ver, placement);
828+
Package existing = m_packageManager.getPackage(packageId, ver, location);
829829
if (options & FetchOptions.printOnly) {
830830
if (existing && existing.version_ != ver)
831831
logInfo("A new version for %s is available (%s -> %s). Run \"%s\" to switch.",
@@ -863,7 +863,7 @@ class Dub {
863863
if (dstpath.existsFile())
864864
{
865865
m_packageManager.refresh(false);
866-
return m_packageManager.getPackage(packageId, ver, dstpath);
866+
return m_packageManager.getPackage(packageId, ver, location);
867867
}
868868

869869
// repeat download on corrupted zips, see #1336

source/dub/packagemanager.d

+34
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class PackageManager {
195195
}
196196

197197
/// ditto
198+
deprecated("Use the overload that takes a `PlacementLocation`")
198199
Package getPackage(string name, Version ver, NativePath path)
199200
{
200201
foreach (p; getPackageIterator(name)) {
@@ -205,6 +206,15 @@ class PackageManager {
205206
return null;
206207
}
207208

209+
/// Ditto
210+
Package getPackage(string name, Version ver, PlacementLocation loc)
211+
{
212+
// Bare mode
213+
if (loc >= this.m_repositories.length)
214+
return null;
215+
return this.m_repositories[loc].lookup(name, ver);
216+
}
217+
208218
/// ditto
209219
deprecated("Use the overload that accepts a `Version` as second argument")
210220
Package getPackage(string name, string ver, NativePath path)
@@ -1175,6 +1185,30 @@ private struct Location {
11751185
logDiagnostic("Failed to enumerate %s packages: %s", path.toNativeString(), e.toString());
11761186
}
11771187

1188+
/**
1189+
* Looks up already-loaded packages at a specific version
1190+
*
1191+
* Looks up a package according to this `Location`'s priority,
1192+
* that is, packages from the search path and local packages
1193+
* have the highest priority.
1194+
*
1195+
* Params:
1196+
* name = The full name of the package to look up
1197+
* ver = The version to look up
1198+
*
1199+
* Returns:
1200+
* A `Package` if one was found, `null` if none exists.
1201+
*/
1202+
private inout(Package) lookup(string name, Version ver) inout {
1203+
foreach (pkg; this.localPackages)
1204+
if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.strict))
1205+
return pkg;
1206+
foreach (pkg; this.fromPath)
1207+
if (pkg.name == name && pkg.version_.matches(ver, VersionMatchMode.strict))
1208+
return pkg;
1209+
return null;
1210+
}
1211+
11781212
/**
11791213
* Get the final destination a specific package needs to be stored in.
11801214
*

0 commit comments

Comments
 (0)