diff --git a/source/app.d b/source/app.d index 2256407..660cca1 100644 --- a/source/app.d +++ b/source/app.d @@ -144,11 +144,25 @@ if( install_version.length ) dub.install(name, new Dependency(install_version), location); else { try dub.install(name, new Dependency(">=0.0.0"), location); - catch(Exception) dub.install(name, new Dependency("~master"), location); + catch(Exception e){ + logInfo("Installing a release version failed: %s", e.msg); + logInfo("Retry with ~master..."); + dub.install(name, new Dependency("~master"), location); + } } break; case "uninstall": - enforce("Not implemented."); + enforce(args.length >= 2, "Missing package name."); + /*auto location = InstallLocation.UserWide; + auto name = args[1]; + enforce(!install_local || !install_system, "Cannot install locally and system wide at the same time."); + if( install_local ) location = InstallLocation.Local; + else if( install_system ) location = InstallLocation.SystemWide; + if( install_version.length ) dub.uninstall(name, new Dependency(install_version), location); + else { + assert(false); + }*/ + enforce(false, "Not implemented."); break; case "add-local": enforce(args.length >= 3, "Missing arguments."); diff --git a/source/dub/dub.d b/source/dub/dub.d index d92963f..ada3624 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -191,16 +191,17 @@ auto pinfo = m_packageSupplier.packageJson(packageId, dep); string ver = pinfo["version"].get!string; - logInfo("Installing %s %s...", packageId, ver); + logInfo("Downloading %s %s...", packageId, ver); - logDebug("Aquiring package zip file"); + logDebug("Acquiring package zip file"); auto dload = m_root ~ ".dub/temp/downloads"; - auto tempFile = m_tempPath ~ ("dub-download-"~packageId~"-"~ver~".zip"); - string sTempFile = to!string(tempFile); - if(exists(sTempFile)) remove(sTempFile); + auto tempfname = packageId ~ "-" ~ (ver.startsWith('~') ? ver[1 .. $] : ver) ~ ".zip"; + auto tempFile = m_tempPath ~ tempfname; + if( existsFile(tempFile) ) removeFile(tempFile); m_packageSupplier.storePackage(tempFile, packageId, dep); // Q: continue on fail? - scope(exit) remove(sTempFile); + scope(exit) removeFile(tempFile); + logInfo("Installing %s %s...", packageId, ver); m_packageManager.install(tempFile, pinfo, location); } diff --git a/source/dub/installation.d b/source/dub/installation.d index 524c40f..af92ca9 100644 --- a/source/dub/installation.d +++ b/source/dub/installation.d Binary files differ diff --git a/source/dub/package_.d b/source/dub/package_.d index b949b39..8fceb36 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -187,8 +187,6 @@ void writeJson(Path path) { auto dstFile = openFile((path~PackageJsonFilename).toString(), FileMode.CreateTrunc); scope(exit) dstFile.close(); - Appender!string js; - toPrettyJson(js, m_meta); - dstFile.write( js.data ); + dstFile.writePrettyJsonString(m_meta); } } \ No newline at end of file diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index 61dcdd4..5e5362e 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -16,6 +16,7 @@ import std.conv; import std.exception; import std.file; +import std.string; import std.zip; import vibe.core.file; import vibe.core.log; @@ -169,7 +170,7 @@ } if( existsFile(destination) ) - throw new Exception(package_name~" needs to be uninstalled prior installation."); + throw new Exception(format("%s %s needs to be uninstalled prior installation.", package_name, package_version)); // open zip file ZipArchive archive; diff --git a/source/dub/packagesupplier.d b/source/dub/packagesupplier.d index b3f6edf..f72ada5 100644 --- a/source/dub/packagesupplier.d +++ b/source/dub/packagesupplier.d @@ -39,13 +39,13 @@ enforce(path.absolute); logInfo("Storing package '"~packageId~"', version requirements: %s", dep); auto filename = bestPackageFile(packageId, dep); - enforce( exists(to!string(filename)) ); - copy(to!string(filename), to!string(path)); + enforce(existsFile(filename)); + copyFile(filename, path); } Json packageJson(const string packageId, const Dependency dep) { auto filename = bestPackageFile(packageId, dep); - return jsonFromZip(to!string(filename), "package.json"); + return jsonFromZip(filename, "package.json"); } private Path bestPackageFile( const string packageId, const Dependency dep) const { @@ -64,7 +64,7 @@ auto fileName = m_path ~ (packageId ~ "_" ~ to!string(bestVersion) ~ ".zip"); - if(bestVersion == Version.RELEASE || !exists(to!string(fileName))) + if(bestVersion == Version.RELEASE || !existsFile(fileName)) throw new Exception("No matching package found"); logDebug("Found best matching package: '%s'", fileName); diff --git a/source/dub/project.d b/source/dub/project.d index aae2f8e..8a5f0d7 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -416,9 +416,7 @@ if( !exists(dubpath.toNativeString()) ) mkdir(dubpath.toNativeString()); auto dstFile = openFile((dubpath~"dub.json").toString(), FileMode.CreateTrunc); scope(exit) dstFile.close(); - Appender!string js; - toPrettyJson(js, m_json); - dstFile.write( js.data ); + dstFile.writePrettyJsonString(m_json); } catch( Exception e ){ logWarn("Could not write .dub/dub.json."); } diff --git a/source/dub/utils.d b/source/dub/utils.d index d890bf4..f6f4fd7 100644 --- a/source/dub/utils.d +++ b/source/dub/utils.d @@ -38,7 +38,7 @@ return parseJson(text); } -package Json jsonFromZip(string zip, string filename) { +package Json jsonFromZip(Path zip, string filename) { auto f = openFile(zip, FileMode.Read); ubyte[] b = new ubyte[cast(uint)f.leastSize]; f.read(b); @@ -52,7 +52,7 @@ { auto f = openFile(path, FileMode.CreateTrunc); scope(exit) f.close(); - toPrettyJson(f, json); + f.writePrettyJsonString(json); } package bool isPathFromZip(string p) {