fix: CWD restore, install error checks, fetch EINTR

- build.cpp: save/restore CWD on both success and failure paths
- install.cpp: check error_code after each filesystem op, abort on failure
- install.cpp: check write_installed() return value
- fetch.cpp: EINTR retry loop on both waitpid calls (exec_cmd + exec_capture)
This commit is contained in:
2026-07-30 05:31:59 -04:00
parent 6c993d2d17
commit c276465f3a
2 changed files with 12 additions and 4 deletions
+5 -2
View File
@@ -2,6 +2,7 @@
#include "kappa/paths.hpp" #include "kappa/paths.hpp"
#include <array> #include <array>
#include <cerrno>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <filesystem> #include <filesystem>
@@ -29,7 +30,8 @@ static int exec_cmd(const std::vector<std::string>& argv) {
} }
if (pid < 0) { return -1; } if (pid < 0) { return -1; }
int status = 0; int status = 0;
waitpid(pid, &status, 0); pid_t w;
do { w = waitpid(pid, &status, 0); } while (w == -1 && errno == EINTR);
return WIFEXITED(status) ? WEXITSTATUS(status) : -1; return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
} }
@@ -61,7 +63,8 @@ static std::string exec_capture(const std::vector<std::string>& argv) {
result += buf.data(); result += buf.data();
} }
close(pipefd[0]); close(pipefd[0]);
waitpid(pid, nullptr, 0); pid_t w;
do { w = waitpid(pid, nullptr, 0); } while (w == -1 && errno == EINTR);
if (!result.empty() && result.back() == '\n') { result.pop_back(); } if (!result.empty() && result.back() == '\n') { result.pop_back(); }
return result; return result;
+7 -2
View File
@@ -42,21 +42,26 @@ InstallResult install(const resolve::BuildStep& step,
auto src = work_dir / "destdir"; auto src = work_dir / "destdir";
if (fs::exists(src)) { if (fs::exists(src)) {
for (auto& entry : fs::recursive_directory_iterator(src, ec)) { for (auto& entry : fs::recursive_directory_iterator(src, ec)) {
if (ec) { break; }
auto rel = fs::relative(entry.path(), src); auto rel = fs::relative(entry.path(), src);
auto target = dest / rel; auto target = dest / rel;
if (entry.is_directory()) { if (entry.is_directory()) {
fs::create_directories(target, ec); fs::create_directories(target, ec);
} else { } else {
fs::create_directories(target.parent_path(), ec); fs::create_directories(target.parent_path(), ec);
fs::rename(entry.path(), target, ec); if (!ec) { fs::rename(entry.path(), target, ec); }
} }
if (ec) { break; }
} }
} }
auto entries = read_installed(); auto entries = read_installed();
entries.push_back({step.name, step.resolved.original.version, entries.push_back({step.name, step.resolved.original.version,
hash, step.resolved.original.provides}); hash, step.resolved.original.provides});
write_installed(entries); if (!write_installed(entries)) {
result.error = "failed to write installed DB";
return result;
}
std::vector<std::string> hashes; std::vector<std::string> hashes;
for (auto& e : entries) { hashes.push_back(e.hash); } for (auto& e : entries) { hashes.push_back(e.hash); }