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

Simplify PackageManager.getPackagePath #2802

Merged
merged 1 commit into from
Jan 17, 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
Simplify PackageManager.getPackagePath
All callers ended up appending to the returned path,
so just do it in getPackagePath and save ourself some trouble.
  • Loading branch information
Geod24 committed Jan 16, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit deeb112df9f95b550d8877852901475275e51e93
20 changes: 7 additions & 13 deletions source/dub/packagemanager.d
Original file line number Diff line number Diff line change
@@ -430,9 +430,6 @@ class PackageManager {

string gitReference = repo.ref_.chompPrefix("~");
NativePath destination = this.getPackagePath(PlacementLocation.user, name, repo.ref_);
// For libraries leaking their import path
destination ~= name;
destination.endsWithSlash = true;

foreach (p; getPackageIterator(name)) {
if (p.path == destination) {
@@ -725,13 +722,12 @@ class PackageManager {
Package store(NativePath src, PlacementLocation dest, string name, Version vers)
{
NativePath dstpath = this.getPackagePath(dest, name, vers.toString());
ensureDirectory(dstpath);
// For libraries leaking their import path
dstpath = dstpath ~ name;
ensureDirectory(dstpath.parentPath());
const lockPath = dstpath.parentPath() ~ ".lock";

// possibly wait for other dub instance
import core.time : seconds;
auto lock = lockFile(dstpath.toNativeString() ~ ".lock", 30.seconds);
auto lock = lockFile(lockPath.toNativeString(), 30.seconds);
if (dstpath.existsFile()) {
return this.getPackage(name, vers, dest);
}
@@ -1441,12 +1437,11 @@ package struct Location {
return pkg;

string versStr = vers.toString();
const lookupName = name.main;
const path = this.getPackagePath(lookupName, versStr) ~ (lookupName ~ "/");
const path = this.getPackagePath(name.main, versStr);
if (!path.existsDirectory())
return null;

logDiagnostic("Lazily loading package %s:%s from %s", lookupName, vers, path);
logDiagnostic("Lazily loading package %s:%s from %s", name.main, vers, path);
auto p = mgr.load(path);
enforce(
p.version_ == vers,
@@ -1463,13 +1458,12 @@ package struct Location {
* which expects their containing folder to have an exact name and use
* `importPath "../"`.
*
* Hence the final format should be `$BASE/$NAME-$VERSION/$NAME`,
* but this function returns `$BASE/$NAME-$VERSION/`
* Hence the final format returned is `$BASE/$NAME/$VERSION/$NAME`,
* `$BASE` is `this.packagePath`.
*/
NativePath getPackagePath (string name, string vers)
{
NativePath result = this.packagePath ~ name ~ vers;
NativePath result = this.packagePath ~ name ~ vers ~ name;
result.endsWithSlash = true;
return result;
}
2 changes: 0 additions & 2 deletions source/dub/test/base.d
Original file line number Diff line number Diff line change
@@ -335,8 +335,6 @@ package class TestPackageManager : PackageManager

string gitReference = repo.ref_.chompPrefix("~");
NativePath destination = this.getPackagePath(PlacementLocation.user, name, repo.ref_);
destination ~= name;
destination.endsWithSlash = true;

foreach (p; getPackageIterator(name))
if (p.path == destination)
Loading