diff options
author | dec05eba <dec05eba@protonmail.com> | 2017-12-12 17:33:03 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2017-12-12 17:34:16 +0100 |
commit | f3b7b7d34b3bf2b1be18914577c96b66dead379a (patch) | |
tree | f24a08256bc959929d51045eb49283fcab7e8b54 /src/GlobalLib.cpp | |
parent | cfe578ec12198d09a9a89a2e0b40bccaa06aa8ae (diff) |
Download and extract missing dependencies from github
Using libcurl and libarchive
Diffstat (limited to 'src/GlobalLib.cpp')
-rw-r--r-- | src/GlobalLib.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
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<bool>::Err(errMsg); + return Result<bool>::Err(errMsg, DependencyError::DEPENDENCY_NOT_FOUND); } case FileType::REGULAR: { @@ -57,7 +59,7 @@ namespace sibs { Result<bool> packageExistsResult = validatePackageExists(globalLibRootDir, name); if(packageExistsResult.isErr()) - return Result<string>::Err(packageExistsResult.getErrMsg()); + return Result<string>::Err(packageExistsResult); string packageDir = globalLibRootDir + "/"; packageDir += name; @@ -76,7 +78,7 @@ namespace sibs }); if(foundVersion.empty()) - return Result<string>::Err("Global lib dependency found, but version doesn't match dependency version"); + return Result<string>::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<string>::Ok(staticLibPath); } } + + Result<bool> 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<bool> 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 |