From 6404fcf0c12b10a5357f1140ad658e7d43e10310 Mon Sep 17 00:00:00 2001 From: Kaiden Fey Date: Sun, 6 Sep 2020 20:25:05 +0200 Subject: stage1: implementing available root iteration --- stage1/lib/root.h | 51 +++++++++++++++++++++++++++++++++++++++++---------- stage1/main.cpp | 8 ++++++-- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/stage1/lib/root.h b/stage1/lib/root.h index 3fbca0c5367..c6470bccdfa 100644 --- a/stage1/lib/root.h +++ b/stage1/lib/root.h @@ -1,9 +1,11 @@ -#include +#include #include #include -#include +#include +#include using std::string; +using std::vector; namespace fs = std::filesystem; /** Root build type */ @@ -22,15 +24,44 @@ struct root_t { }; -root_t get_root(string path) +vector get_roots_for_path(string path) { - for(auto &entry: fs::recursive_directory_iterator(path)) { - std::cout << entry.path() << std::endl; + vector roots; + + for(auto &entry: fs::directory_iterator(path)) { + auto path = entry.path(); + + if (path.extension() == ".nix") { + // simple root + roots.push_back(root_t { + path.filename(), + path.string(), + FULL_NIXOS, + }); + + } else { + path /= "default.nix"; + bool exists = fs::exists(path); + path = path.parent_path(); + + if (exists) { + // nested single root + roots.push_back(root_t { + path.filename(), + path.string(), + FULL_NIXOS, + }); + } else { + // nested single root + roots.push_back(root_t { + path.filename(), + path.string(), + COLLECTION, + }); + } + } + } - return root_t { - "hyperion", - "roots/hyperion/default.nix", - FULL_NIXOS, - }; + return roots; } diff --git a/stage1/main.cpp b/stage1/main.cpp index 6f2cd57fae8..b59582f88fb 100644 --- a/stage1/main.cpp +++ b/stage1/main.cpp @@ -5,9 +5,13 @@ int main(int argn, char **argv) { std::cout << "I am a builder!" << std::endl; - get_root("/Users/spacekookie/Projects/code/libkookie/roots"); + auto v = get_roots_for_path("/Users/spacekookie/Projects/code/libkookie/roots"); + std::cout << "uwu! " << v.size() << std::endl; - std::cout << "uwu!" << std::endl; + for (auto &entry : v) { + std::cout << entry.name << ": " << entry.path << std::endl; + } + return 0; } -- cgit v1.2.3