diff --git a/source/dub/dub.d b/source/dub/dub.d index a9d5c51..849538d 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -581,6 +581,13 @@ if (!placement.existsFile()) mkdirRecurse(placement.toNativeString()); Path dstpath = placement ~ (packageId ~ "-" ~ clean_package_version); + if (!dstpath.existsFile()) + mkdirRecurse(dstpath.toNativeString()); + + // Support libraries typically used with git submodules like ae. + // Such libraries need to have ".." as import path but this can create + // import path leakage. + dstpath = dstpath ~ packageId; auto lock = lockFile(dstpath.toNativeString() ~ ".lock", 30.seconds); // possibly wait for other dub instance if (dstpath.existsFile()) diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 08331b2..aa5f921 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -203,9 +203,19 @@ bool isManagedPackage(Package pack) const { auto ppath = pack.basePackage.path; + return isManagedPath(ppath); + } + + /** Determines if a specifc path is within a DUB managed package folder. + + By default, managed folders are "~/.dub/packages" and + "/var/lib/dub/packages". + */ + bool isManagedPath(Path path) + const { foreach (rep; m_repositories) { auto rpath = rep.packagePath; - if (ppath.startsWith(rpath)) + if (path.startsWith(rpath)) return true; } return false; @@ -532,8 +542,20 @@ logDebug("iterating dir %s", path.toNativeString()); try foreach( pdir; iterateDirectory(path) ){ logDebug("iterating dir %s entry %s", path.toNativeString(), pdir.name); - if( !pdir.isDirectory ) continue; + if (!pdir.isDirectory) continue; + auto pack_path = path ~ (pdir.name ~ "/"); + + if (isManagedPath(path)) { + // Search for a single directory within this directory which happen to be a prefix of pdir + // This is to support new folder structure installed over the ancient one. + foreach (subdir; iterateDirectory(path ~ (pdir.name ~ "/"))) + if (subdir.isDirectory && pdir.name.startsWith(subdir.name)) {// eg: package vibe-d will be in "vibe-d-x.y.z/vibe-d" + pack_path ~= subdir.name ~ "/"; + break; + } + } + auto packageFile = Package.findPackageFile(pack_path); if (packageFile.empty) continue; Package p; diff --git a/test/issue502-root-import/dub.json b/test/issue502-root-import/dub.json new file mode 100644 index 0000000..cdd4b0b --- /dev/null +++ b/test/issue502-root-import/dub.json @@ -0,0 +1,7 @@ +{ + "name": "issue502-root-import", + "dependencies": + { + "gitcompatibledubpackage": "~>1.0" + } +} \ No newline at end of file diff --git a/test/issue502-root-import/source/app.d b/test/issue502-root-import/source/app.d new file mode 100644 index 0000000..9241919 --- /dev/null +++ b/test/issue502-root-import/source/app.d @@ -0,0 +1,10 @@ +import gitcompatibledubpackage.subdir.file; + +void main(string[] args) +{ +} + +unittest +{ + assert(!hasTheWorldExploded()); +} \ No newline at end of file