From 198677fc184a0778aae7fd779c43c3f35327443d Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 5 Sep 2023 17:43:28 -0300 Subject: [PATCH] some thoughts about post unachivation, nothing useful yet --- src/dependency.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- src/dependency.h | 3 ++- src/project.h | 2 ++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/dependency.cpp b/src/dependency.cpp index 5d3fce8..3fe4033 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -44,7 +44,32 @@ bool Dependency::prepare(const std::filesystem::path& source, const std::filesys const std::string& owner = results[3]; const std::string& repo = results[4]; - return downloadRepo(destination, protocol, host, owner, repo); + std::filesystem::path temp; + bool success = downloadRepo(destination, protocol, host, owner, repo, temp); + if (success) { + Project::info("Successfully obtained project " + path); + + switch (type) { + case Type::automatic: + if (std::filesystem::exists(temp/"mason.json")) + type = Type::mason; + else + type = Type::simple; + + break; + case Type::mason: + if (std::filesystem::exists(temp/"mason.json")) + break; + else + Project::warn("Project " + path + " is supposed to me a mason project, but no mason.json was found in the project directory"); + + break; + case Type::simple: + break; + } + } + + return success; } else { Project::info("checking project at path " + path); std::filesystem::directory_entry srcDir(source / path); @@ -62,7 +87,8 @@ bool Dependency::downloadRepo( const std::string& protocol, const std::string& host, const std::string& owner, - const std::string& repo + const std::string& repo, + std::filesystem::path& out ) { nlohmann::json info; Project::info("Trying Gitea v1 API"); @@ -83,9 +109,17 @@ bool Dependency::downloadRepo( Project::info("Successfully downloaded " + archivePath.string()); res = extract(archivePath, destination/build); - if (!res) { + if (res) { + out = destination/build/repo; + if (!std::filesystem::is_directory(out)) { + Project::error("Extracted archive " + fileName + " but the content is unexpected"); + res = false; + } + } else { Project::error("Couldn't extract archive " + fileName); } + + return res; } } else { res = false; @@ -264,6 +298,9 @@ bool Dependency::extract(const std::filesystem::path& source, const std::filesys std::string fileName(archive_entry_pathname(entry)); std::filesystem::path filePath = destination/fileName; Project::debug("Extracting " + filePath.string()); + if (std::filesystem::exists(filePath)) + Project::minor(filePath.string() + " exists, overwriting"); + archive_entry_set_pathname_utf8(entry, filePath.c_str()); r = archive_write_header(ext, entry); diff --git a/src/dependency.h b/src/dependency.h index d3e0d86..bd19565 100644 --- a/src/dependency.h +++ b/src/dependency.h @@ -45,7 +45,8 @@ private: const std::string& protocol, const std::string& host, const std::string& owner, - const std::string& repo + const std::string& repo, + std::filesystem::path& out ); bool repoGiteaApi1( const std::string& protocol, diff --git a/src/project.h b/src/project.h index 2ea73e8..a5e1fe3 100644 --- a/src/project.h +++ b/src/project.h @@ -41,6 +41,8 @@ public: static void fatal(const std::string& message); static void printLog(); + static void addProject(const std::filesystem::path& location, const std::filesystem::path& destination); + private: void parse(const nlohmann::json& json); void createDepencencyFromString(const std::string& entry);