some thoughts about post unachivation, nothing useful yet

This commit is contained in:
Blue 2023-09-05 17:43:28 -03:00
parent 5ee7ae7f73
commit 198677fc18
Signed by: blue
GPG Key ID: 9B203B252A63EE38
3 changed files with 44 additions and 4 deletions

View File

@ -44,7 +44,32 @@ bool Dependency::prepare(const std::filesystem::path& source, const std::filesys
const std::string& owner = results[3]; const std::string& owner = results[3];
const std::string& repo = results[4]; 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 { } else {
Project::info("checking project at path " + path); Project::info("checking project at path " + path);
std::filesystem::directory_entry srcDir(source / path); std::filesystem::directory_entry srcDir(source / path);
@ -62,7 +87,8 @@ bool Dependency::downloadRepo(
const std::string& protocol, const std::string& protocol,
const std::string& host, const std::string& host,
const std::string& owner, const std::string& owner,
const std::string& repo const std::string& repo,
std::filesystem::path& out
) { ) {
nlohmann::json info; nlohmann::json info;
Project::info("Trying Gitea v1 API"); Project::info("Trying Gitea v1 API");
@ -83,9 +109,17 @@ bool Dependency::downloadRepo(
Project::info("Successfully downloaded " + archivePath.string()); Project::info("Successfully downloaded " + archivePath.string());
res = extract(archivePath, destination/build); 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); Project::error("Couldn't extract archive " + fileName);
} }
return res;
} }
} else { } else {
res = false; 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::string fileName(archive_entry_pathname(entry));
std::filesystem::path filePath = destination/fileName; std::filesystem::path filePath = destination/fileName;
Project::debug("Extracting " + filePath.string()); 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()); archive_entry_set_pathname_utf8(entry, filePath.c_str());
r = archive_write_header(ext, entry); r = archive_write_header(ext, entry);

View File

@ -45,7 +45,8 @@ private:
const std::string& protocol, const std::string& protocol,
const std::string& host, const std::string& host,
const std::string& owner, const std::string& owner,
const std::string& repo const std::string& repo,
std::filesystem::path& out
); );
bool repoGiteaApi1( bool repoGiteaApi1(
const std::string& protocol, const std::string& protocol,

View File

@ -41,6 +41,8 @@ public:
static void fatal(const std::string& message); static void fatal(const std::string& message);
static void printLog(); static void printLog();
static void addProject(const std::filesystem::path& location, const std::filesystem::path& destination);
private: private:
void parse(const nlohmann::json& json); void parse(const nlohmann::json& json);
void createDepencencyFromString(const std::string& entry); void createDepencencyFromString(const std::string& entry);