fix(install): stream DEB members; extend the VoidLibrary build branch
This commit is contained in:
1 parent
081cff7301
commit
e63ec85809
5 files changed
+112
-19
No files matched your search
+91
-19
@@ -12,6 +12,8 @@
|
||||
#include <Void/Text/Str.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <format>
|
||||
#include <set>
|
||||
#include <unistd.h>
|
||||
@@ -166,26 +168,78 @@ write_stored_zip(const std::filesystem::path &output,
|
||||
return Platform::atomic_write_file(output, zip, true);
|
||||
}
|
||||
|
||||
void append_ar_member(std::string &out, std::string_view name, std::string_view data) {
|
||||
std::string ar_member_header(std::string_view name, std::uint64_t size) {
|
||||
std::string header;
|
||||
std::string padded_name{name};
|
||||
padded_name.push_back('/');
|
||||
header.reserve(60);
|
||||
header += padded_name;
|
||||
header.resize(16, ' ');
|
||||
header += std::format("{:<12}", 0); // mtime
|
||||
header += std::format("{:<6}", 0); // uid
|
||||
header += std::format("{:<6}", 0); // gid
|
||||
header += std::format("{:<8}", 100644); // mode
|
||||
header += std::format("{:<10}", data.size()); // size
|
||||
header += std::format("{:<12}", 0); // mtime
|
||||
header += std::format("{:<6}", 0); // uid
|
||||
header += std::format("{:<6}", 0); // gid
|
||||
header += std::format("{:<8}", 100644); // mode
|
||||
header += std::format("{:<10}", size); // size
|
||||
header += "`\n";
|
||||
out += header;
|
||||
return header;
|
||||
}
|
||||
|
||||
void append_ar_member(std::string &out, std::string_view name, std::string_view data) {
|
||||
out += ar_member_header(name, data.size());
|
||||
out += data;
|
||||
if (data.size() % 2 != 0) {
|
||||
out.push_back('\n');
|
||||
}
|
||||
}
|
||||
|
||||
void append_ar_member_to_stream(std::ostream &out, std::string_view name,
|
||||
std::string_view data) {
|
||||
out << ar_member_header(name, data.size());
|
||||
out.write(data.data(), static_cast<std::streamsize>(data.size()));
|
||||
if (data.size() % 2 != 0) {
|
||||
out.put('\n');
|
||||
}
|
||||
}
|
||||
|
||||
// Streams a file into an ar member so payloads of any size bypass read limits.
|
||||
Void::Result::Result<void, Void::Result::Error>
|
||||
append_ar_member_file(std::ostream &out, std::string_view name,
|
||||
const std::filesystem::path &source) {
|
||||
std::error_code ec;
|
||||
const auto size = std::filesystem::file_size(source, ec);
|
||||
if (ec) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::map_errno_to_system_code(ec.value()),
|
||||
std::format("cannot stat '{}': {}", source.string(), ec.message()), ec.value())};
|
||||
}
|
||||
std::ifstream in{source, std::ios::binary};
|
||||
if (!in) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("cannot open '{}'", source.string()))};
|
||||
}
|
||||
out << ar_member_header(name, size);
|
||||
std::array<char, 64 * 1024> buffer{};
|
||||
std::uint64_t copied = 0;
|
||||
while (in) {
|
||||
in.read(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||
const auto count = in.gcount();
|
||||
if (count > 0) {
|
||||
out.write(buffer.data(), count);
|
||||
copied += static_cast<std::uint64_t>(count);
|
||||
}
|
||||
}
|
||||
if (copied != size) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("short read while archiving '{}'", source.string()))};
|
||||
}
|
||||
if (size % 2 != 0) {
|
||||
out.put('\n');
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// ── Minimal native RPM writer (uncompressed newc cpio payload) ──────────────────────────────
|
||||
namespace rpm {
|
||||
|
||||
@@ -480,20 +534,38 @@ write_deb_package(const std::filesystem::path &output, const InstallOptions &opt
|
||||
return std::unexpected{control.error()};
|
||||
}
|
||||
|
||||
auto data_bytes = Void::FileSystem::read_file(data_tar);
|
||||
if (!data_bytes) {
|
||||
return std::unexpected{data_bytes.error()};
|
||||
// Stream the members: package payloads can exceed in-memory read limits.
|
||||
const auto temp_deb = output.parent_path() / (output.filename().string() + ".tmp");
|
||||
std::ofstream deb{temp_deb, std::ios::binary | std::ios::trunc};
|
||||
if (!deb) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("cannot create '{}'", temp_deb.string()))};
|
||||
}
|
||||
auto control_bytes = Void::FileSystem::read_file(control_tar);
|
||||
if (!control_bytes) {
|
||||
return std::unexpected{control_bytes.error()};
|
||||
deb << "!<arch>\n";
|
||||
append_ar_member_to_stream(deb, "debian-binary", "2.0\n");
|
||||
if (auto member = append_ar_member_file(deb, "control.tar", control_tar); !member) {
|
||||
return std::unexpected{member.error()};
|
||||
}
|
||||
|
||||
std::string deb = "!<arch>\n";
|
||||
append_ar_member(deb, "debian-binary", "2.0\n");
|
||||
append_ar_member(deb, "control.tar", *control_bytes);
|
||||
append_ar_member(deb, "data.tar", *data_bytes);
|
||||
return Platform::atomic_write_file(output, deb, true);
|
||||
if (auto member = append_ar_member_file(deb, "data.tar", data_tar); !member) {
|
||||
return std::unexpected{member.error()};
|
||||
}
|
||||
deb.flush();
|
||||
deb.close();
|
||||
if (!deb) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::SystemErrorCode::io_error,
|
||||
std::format("failed writing '{}'", temp_deb.string()))};
|
||||
}
|
||||
std::error_code rename_ec;
|
||||
std::filesystem::rename(temp_deb, output, rename_ec);
|
||||
if (rename_ec) {
|
||||
return std::unexpected{Void::System::make_system_error(
|
||||
Void::System::map_errno_to_system_code(rename_ec.value()),
|
||||
std::format("cannot publish '{}': {}", output.string(), rename_ec.message()),
|
||||
rename_ec.value())};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Canonical short message signed for installer archives (independent of archive size).
|
||||
|
||||
Reference in new issue
Block a user