diff --git a/source/dub/dub.d b/source/dub/dub.d index e77ec2d..05e2b0c 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -189,7 +189,7 @@ string[string] installedPackages() const { return m_project.installedPackagesIDs(); } /// Installs the package matching the dependency into the application. - Package install(string packageId, const Dependency dep, InstallLocation location = InstallLocation.projectLocal) + Package install(string packageId, const Dependency dep, InstallLocation location) { Json pinfo; PackageSupplier supplier; @@ -206,7 +206,6 @@ Path install_path; final switch (location) { case InstallLocation.local: install_path = m_cwd; break; - case InstallLocation.projectLocal: install_path = m_project.mainPackage.path ~ ".dub/packages/"; break; case InstallLocation.userWide: install_path = m_userDubPath ~ "packages/"; break; case InstallLocation.systemWide: install_path = m_systemDubPath ~ "packages/"; break; } @@ -259,13 +258,13 @@ /// Note: as wildcard string only "*" is supported. /// @param location_ void uninstall(string package_id, string version_, InstallLocation location_) { - /+enforce(!package_id.empty); + enforce(!package_id.empty); Package[] packages; const bool wildcardOrEmpty = version_ == UninstallVersionWildcard || version_.empty; if(location_ == InstallLocation.local) { // Try folder named like the package_id in the cwd. try { - Package pack = new Package(InstallLocation.local, Path(package_id)); + Package pack = new Package(Path(package_id)); if(!wildcardOrEmpty && to!string(pack.vers) != version_) { logError("Installed package is of different version, uninstallation aborted."); logError("Installed: %s, provided %s@", pack.vers, version_); @@ -275,8 +274,8 @@ } catch {/* noop */} } else { // Use package manager - foreach(pack; m_packageManager.getPackageIterator(package_id)){ - if( pack.installLocation == location_ && (wildcardOrEmpty || pack.vers == version_ )) { + foreach(pack; m_packageManager.getPackageIterator(package_id)) { + if( wildcardOrEmpty || pack.vers == version_ ) { packages ~= pack; } } @@ -302,7 +301,7 @@ logInfo("Uninstalled %s, version %s.", package_id, pack.vers); } catch logError("Failed to uninstall %s, version %s. Continuing with other packages (if any).", package_id, pack.vers); - }+/ + } } void addLocalPackage(string path, string ver, bool system) diff --git a/source/dub/package_.d b/source/dub/package_.d index 32541e1..a8bd04c 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -32,9 +32,6 @@ /// Packages installed with 'local' will be placed in the current folder /// using the package name as destination. local, - /// Packages with 'projectLocal' will be placed in a folder managed by - /// dub (i.e. inside the .dub subfolder). - projectLocal, /// Packages with 'userWide' will be placed in a folder accessible by /// all of the applications from the current user. userWide, diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 4305907..e329ada 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -157,7 +157,7 @@ return &iterator; } - Package install(Path zip_file_path, Json package_info, /*InstallLocation location*/Path destination) + Package install(Path zip_file_path, Json package_info, Path destination) { auto package_name = package_info.name.get!string(); auto package_version = package_info["version"].get!string(); @@ -183,11 +183,12 @@ // In a github zip, the actual contents are in a subfolder Path zip_prefix; - foreach(ArchiveMember am; archive.directory) + foreach(ArchiveMember am; archive.directory) { if( Path(am.name).head == PathEntry(PackageJsonFilename) ){ zip_prefix = Path(am.name)[0 .. 1]; break; } + } if( zip_prefix.empty ){ // not correct zip packages HACK @@ -255,38 +256,34 @@ void uninstall(in Package pack) { - /+logTrace("Uninstall %s, version %s, path '%s'", pack.name, pack.vers, pack.path); + logTrace("Uninstall %s, version %s, path '%s'", pack.name, pack.vers, pack.path); enforce(!pack.path.empty, "Cannot uninstall package "~pack.name~" without a path."); - // remove package from package list - final switch(pack.installLocation){ - case InstallLocation.local: - logTrace("Uninstall local"); - break; - case InstallLocation.projectLocal: - logTrace("Uninstall projectLocal"); - auto pp = pack.name in m_projectPackages; - assert(pp !is null, "Package "~pack.name~" at "~pack.path.toNativeString()~" is not installed in project."); - assert(*pp is pack); - m_projectPackages.remove(pack.name); - break; - case InstallLocation.userWide: - logTrace("Uninstall userWide"); - auto pv = pack.name in m_userPackages; - assert(pv !is null, "Package "~pack.name~" at "~pack.path.toNativeString()~" is not installed in user repository."); - auto idx = countUntil(*pv, pack); - assert(idx < 0 || (*pv)[idx] is pack); - if( idx >= 0 ) *pv = (*pv)[0 .. idx] ~ (*pv)[idx+1 .. $]; - break; - case InstallLocation.systemWide: - logTrace("Uninstall systemWide"); - auto pv = pack.name in m_systemPackages; - assert(pv !is null, "Package "~pack.name~" at "~pack.path.toNativeString()~" is not installed system repository."); - auto idx = countUntil(*pv, pack); - assert(idx < 0 || (*pv)[idx] is pack); - if( idx >= 0 ) *pv = (*pv)[0 .. idx] ~ (*pv)[idx+1 .. $]; - break; + // remove package from repositories' list + bool found = false; + bool removeFrom(Package[] packs, in Package pack) { + auto packPos = countUntil!("a.path == b.path")(packs, pack); + if(packPos != -1) { + packs = std.algorithm.remove(packs, packPos); + return true; + } + return false; } + foreach(repo; m_repositories) { + if(removeFrom(repo.localPackages, pack)) { + found = true; + break; + } + } + if(!found) { + foreach(packsOfId; m_packages) { + if(removeFrom(packsOfId, pack)) { + found = true; + break; + } + } + } + enforce(found, "Cannot uninstall, package not found: '"~ pack.name ~"', path: " ~ to!string(pack.path)); // delete package files physically logTrace("Looking up journal"); @@ -335,7 +332,7 @@ throw new Exception("Alien files found in '"~pack.path.toNativeString()~"', needs to be deleted manually."); rmdir(pack.path.toNativeString()); - logInfo("Uninstalled package: '"~pack.name~"'");+/ + logInfo("Uninstalled package: '"~pack.name~"'"); } Package addLocalPackage(in Path path, in Version ver, LocalPackageType type) diff --git a/source/dub/project.d b/source/dub/project.d index da42b84..8696317 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -565,12 +565,12 @@ static Action conflict(string pkg, in Dependency dep, Dependency[string] context) { - return Action(Type.conflict, pkg, InstallLocation.projectLocal, dep, context); + return Action(Type.conflict, pkg, InstallLocation.userWide, dep, context); } static Action failure(string pkg, in Dependency dep, Dependency[string] context) { - return Action(Type.failure, pkg, InstallLocation.projectLocal, dep, context); + return Action(Type.failure, pkg, InstallLocation.userWide, dep, context); } private this(Type id, string pkg, InstallLocation location, in Dependency d, Dependency[string] issue)