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 --- backend/ninja/Ninja.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'backend') diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 72c1e80..7fb07bf 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -85,9 +85,11 @@ namespace backend { if(dependencies.empty()) return Result::Ok(""); - // TODO: Global library dir should be created during sibs installation string globalLibDir = getHomeDir(); globalLibDir += "/.sibs/lib"; + Result createGlobalLibDirResult = createDirectoryRecursive(globalLibDir.c_str()); + if(createGlobalLibDirResult.isErr()) + return Result::Err(createGlobalLibDirResult); string globalLibLinkerFlags; vector pkgConfigDependencies; @@ -149,6 +151,10 @@ namespace backend if(sourceFiles.empty()) return Result::Err("No source files provided"); + Result createBuildDirResult = createDirectoryRecursive(savePath); + if(createBuildDirResult.isErr()) + return createBuildDirResult; + string ninjaBuildFilePath = savePath; ninjaBuildFilePath += "/build.ninja"; @@ -253,13 +259,9 @@ namespace backend return Result::Err("NOT IMPLEMENTED YET!"); } - bool fileOverwritten = sibs::fileOverwrite(ninjaBuildFilePath.c_str(), sibs::StringView(result.data(), result.size())); - if(!fileOverwritten) - { - string errMsg = "Failed to overwrite ninja build file: "; - errMsg += ninjaBuildFilePath; - return Result::Err(errMsg); - } + Result fileOverwriteResult = sibs::fileOverwrite(ninjaBuildFilePath.c_str(), sibs::StringView(result.data(), result.size())); + if(fileOverwriteResult.isErr()) + return fileOverwriteResult; printf("Created ninja build file: %s\n", ninjaBuildFilePath.c_str()); return Result::Ok(true); -- cgit v1.2.3