1 parent
8aa968eb9f
commit
11850b1a8d
11 files changed
+1569
-160
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace
|
||||
@@ -13,21 +14,26 @@ namespace
|
||||
std::cerr << message << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto root = std::filesystem::temp_directory_path() /
|
||||
("echoion-core-reload-" + std::to_string(::getpid()));
|
||||
("echoion-core-reload-" + std::to_string(::getpid()));
|
||||
std::filesystem::create_directories(root);
|
||||
const auto cleanup = [&root] {
|
||||
std::error_code ec;
|
||||
std::filesystem::permissions(root / "immutable-lib",
|
||||
std::filesystem::perms::owner_all,
|
||||
std::filesystem::perm_options::add, ec);
|
||||
std::filesystem::remove_all(root, ec);
|
||||
};
|
||||
|
||||
::setenv("XDG_CONFIG_HOME", root.c_str(), 1);
|
||||
::setenv("XDG_CACHE_HOME", root.c_str(), 1);
|
||||
::setenv("HOME", root.c_str(), 1);
|
||||
const auto stateDirectory = root / "runtime-state";
|
||||
::setenv("ECHOION_STATE_DIR", stateDirectory.c_str(), 1);
|
||||
const auto ytDlp = root / ".local/share/echoion/yt-dlp/yt-dlp";
|
||||
std::filesystem::create_directories(ytDlp.parent_path());
|
||||
{
|
||||
@@ -35,9 +41,9 @@ int main()
|
||||
output << "#!/bin/sh\necho 2026.01.01\n";
|
||||
}
|
||||
std::filesystem::permissions(ytDlp,
|
||||
std::filesystem::perms::owner_read |
|
||||
std::filesystem::perms::owner_write |
|
||||
std::filesystem::perms::owner_exec);
|
||||
std::filesystem::perms::owner_read |
|
||||
std::filesystem::perms::owner_write |
|
||||
std::filesystem::perms::owner_exec);
|
||||
const auto config = root / "config.json";
|
||||
{
|
||||
std::ofstream output{config};
|
||||
@@ -49,8 +55,27 @@ int main()
|
||||
})";
|
||||
}
|
||||
|
||||
const auto corePath = root / "Echoion.ts";
|
||||
const auto coreDirectory = root / "immutable-lib";
|
||||
std::filesystem::create_directories(coreDirectory);
|
||||
const auto corePath = coreDirectory / "Echoion.ts";
|
||||
std::filesystem::copy_file(ECHOION_TEST_CORE_PATH, corePath);
|
||||
const auto directoryEntries = [&coreDirectory] {
|
||||
std::set<std::filesystem::path> entries;
|
||||
for (const auto& entry :
|
||||
std::filesystem::directory_iterator{coreDirectory}) {
|
||||
entries.insert(entry.path().filename());
|
||||
}
|
||||
return entries;
|
||||
};
|
||||
const auto entriesBeforeLoad = directoryEntries();
|
||||
std::filesystem::permissions(coreDirectory,
|
||||
std::filesystem::perms::owner_read |
|
||||
std::filesystem::perms::owner_exec |
|
||||
std::filesystem::perms::group_read |
|
||||
std::filesystem::perms::group_exec |
|
||||
std::filesystem::perms::others_read |
|
||||
std::filesystem::perms::others_exec,
|
||||
std::filesystem::perm_options::replace);
|
||||
|
||||
Echoion::Host::CoreLoader loader;
|
||||
loader.setConfigPath(config);
|
||||
@@ -58,11 +83,41 @@ int main()
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
}
|
||||
if (directoryEntries() != entriesBeforeLoad) {
|
||||
cleanup();
|
||||
return fail(
|
||||
"initial Core load wrote into the immutable library directory");
|
||||
}
|
||||
loader.enableAutoReload();
|
||||
if (loader.isAutoReloadEnabled()) {
|
||||
cleanup();
|
||||
return fail("auto-reload was enabled for a read-only Core directory");
|
||||
}
|
||||
std::filesystem::permissions(coreDirectory,
|
||||
std::filesystem::perms::owner_all |
|
||||
std::filesystem::perms::group_read |
|
||||
std::filesystem::perms::group_exec |
|
||||
std::filesystem::perms::others_read |
|
||||
std::filesystem::perms::others_exec,
|
||||
std::filesystem::perm_options::replace);
|
||||
loader.enableAutoReload();
|
||||
if (!loader.isAutoReloadEnabled()) {
|
||||
cleanup();
|
||||
return fail(
|
||||
"auto-reload was not enabled for a writable development Core");
|
||||
}
|
||||
loader.disableAutoReload();
|
||||
const auto before = loader.getCore();
|
||||
if (!before) {
|
||||
cleanup();
|
||||
return fail("Core missing after initial load");
|
||||
}
|
||||
if (!std::filesystem::is_regular_file(stateDirectory / "echoion.db") ||
|
||||
std::filesystem::exists(root / "echoion.db") ||
|
||||
!std::filesystem::is_directory(stateDirectory / "logs")) {
|
||||
cleanup();
|
||||
return fail("Core mutable files did not use ECHOION_STATE_DIR");
|
||||
}
|
||||
if (auto result = loader.hotReload(corePath); !result) {
|
||||
cleanup();
|
||||
return fail(result.error().message.c_str());
|
||||
@@ -84,7 +139,8 @@ int main()
|
||||
return fail("invalid replacement unexpectedly activated");
|
||||
}
|
||||
const auto retained = loader.getCore();
|
||||
if (!retained || retained.get() != after.get() || !retained->isInitialized()) {
|
||||
if (!retained || retained.get() != after.get() ||
|
||||
!retained->isInitialized()) {
|
||||
cleanup();
|
||||
return fail("running Core was not retained after failed activation");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user