From f3b7b7d34b3bf2b1be18914577c96b66dead379a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 12 Dec 2017 17:33:03 +0100 Subject: Download and extract missing dependencies from github Using libcurl and libarchive --- src/GlobalLib.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/GlobalLib.cpp') diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index 7503a7a..ce9426d 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -2,6 +2,8 @@ #include "../include/FileUtil.hpp" #include "../backend/ninja/Ninja.hpp" #include "../include/Conf.hpp" +#include "../include/curl.hpp" +#include "../include/Archive.hpp" using namespace std; @@ -18,7 +20,7 @@ namespace sibs { string errMsg = "Global lib dependency not found: "; errMsg += name; - return Result::Err(errMsg); + return Result::Err(errMsg, DependencyError::DEPENDENCY_NOT_FOUND); } case FileType::REGULAR: { @@ -57,7 +59,7 @@ namespace sibs { Result packageExistsResult = validatePackageExists(globalLibRootDir, name); if(packageExistsResult.isErr()) - return Result::Err(packageExistsResult.getErrMsg()); + return Result::Err(packageExistsResult); string packageDir = globalLibRootDir + "/"; packageDir += name; @@ -76,7 +78,7 @@ namespace sibs }); if(foundVersion.empty()) - return Result::Err("Global lib dependency found, but version doesn't match dependency version"); + return Result::Err("Global lib dependency found, but version doesn't match dependency version", DependencyError::DEPENDENCY_VERSION_NO_MATCH); packageDir += "/"; packageDir += version; @@ -156,4 +158,32 @@ namespace sibs return Result::Ok(staticLibPath); } } + + Result GlobalLib::downloadDependency(const Dependency &dependency) + { + string url = "https://github.com/DEC05EBA/"; + url += dependency.name; + url += "/archive/"; + url += dependency.version; + url += ".tar.gz"; + + // TODO: Create library path if it doesn't exist + string libPath = getHomeDir(); + libPath += "/.sibs/lib/"; + libPath += dependency.name; + libPath += "/"; + libPath += dependency.version; + + // TODO: Create archive directory if it doesn't exist + string libArchivedFilePath = getHomeDir(); + libArchivedFilePath += "/.sibs/archive/"; + libArchivedFilePath += dependency.name; + libArchivedFilePath += "/"; + libArchivedFilePath += dependency.version; + Result downloadResult = curl::downloadFile(url.c_str(), libArchivedFilePath.c_str()); + if(downloadResult.isErr()) + return downloadResult; + + return Archive::extract(libArchivedFilePath.c_str(), libPath.c_str()); + } } \ No newline at end of file -- cgit v1.2.3