From f2c70dfaba8d6481e86646080c51b6874d95f14e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 12 Dec 2017 19:46:57 +0100 Subject: Lazily create directories that are needed Directories such as: ~/.sibs ~/.sibs/archive ~/.sibs/lib And directories for each specific library. Also fix bug in getFileContent and fileOverwrite if file already exists --- src/GlobalLib.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/GlobalLib.cpp') diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index ce9426d..177f1b9 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -140,8 +140,11 @@ namespace sibs } else { - // TODO: Create build path if it doesn't exist string debugBuildPath = packageDir + "/build/debug"; + Result createBuildDirResult = createDirectoryRecursive(debugBuildPath.c_str()); + if(createBuildDirResult.isErr()) + return Result::Err(createBuildDirResult); + Result buildFileResult = ninja.createBuildFile(sibsConfig.getPackageName(), sibsConfig.getDependencies(), debugBuildPath.c_str(), linkerFlagCallbackFunc); if (buildFileResult.isErr()) return Result::Err(buildFileResult.getErrMsg()); @@ -167,23 +170,30 @@ namespace sibs 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; + Result createArchiveDirResult = createDirectoryRecursive(libArchivedFilePath.c_str()); + if(createArchiveDirResult.isErr()) + return createArchiveDirResult; + libArchivedFilePath += "/"; libArchivedFilePath += dependency.version; Result downloadResult = curl::downloadFile(url.c_str(), libArchivedFilePath.c_str()); if(downloadResult.isErr()) return downloadResult; + // Create build path. This is done here because we dont want to create it if download fails + Result createLibDirResult = createDirectoryRecursive(libPath.c_str()); + if(createLibDirResult.isErr()) + return createLibDirResult; + return Archive::extract(libArchivedFilePath.c_str(), libPath.c_str()); } } \ No newline at end of file -- cgit v1.2.3