54 lines
2.1 KiB
C++
54 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Void::Build::Package {
|
|
|
|
struct ArchiveLimits {
|
|
std::size_t max_entries{10000};
|
|
std::uint64_t max_file_bytes{512ULL * 1024ULL * 1024ULL};
|
|
std::uint64_t max_total_bytes{2ULL * 1024ULL * 1024ULL * 1024ULL};
|
|
};
|
|
|
|
struct ArchiveExtractionStats {
|
|
std::size_t entries{0};
|
|
std::uint64_t total_bytes{0};
|
|
std::vector<std::filesystem::path> extracted_files;
|
|
};
|
|
|
|
struct ArchiveEntrySpec {
|
|
std::string archive_path; // Relative POSIX path inside archive.
|
|
std::filesystem::path source_file;
|
|
std::uint32_t mode{0644};
|
|
};
|
|
|
|
// Creates a byte-deterministic USTAR/PAX tar archive (canonical mtime/uid/gid, sorted entries)
|
|
// and returns its SHA-256 hex digest (VL-006).
|
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
|
create_deterministic_tar(const std::filesystem::path &output_tar,
|
|
std::vector<ArchiveEntrySpec> entries,
|
|
std::int64_t reproducibility_epoch = 0);
|
|
|
|
// Packages a VBS project's source tree cleanly (retaining build.cpp, optional build.profiles.cpp,
|
|
// build-support/**, and declared sources/headers while excluding .git, build/, .vbs/, secrets).
|
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
|
create_source_package(const std::filesystem::path &project_root,
|
|
const std::filesystem::path &output_tar,
|
|
std::int64_t reproducibility_epoch = 0);
|
|
|
|
// Extracts a tar archive with strict security checks:
|
|
// rejects absolute paths, '..' traversal, symlinks/hardlinks/special files, duplicate paths,
|
|
// and count/size quota overflows. Stages privately and publishes atomically only on full success.
|
|
[[nodiscard]] Void::Result::Result<ArchiveExtractionStats, Void::Result::Error>
|
|
extract_safe_tar(const std::filesystem::path &tar_path,
|
|
const std::filesystem::path &destination_dir, const ArchiveLimits &limits = {});
|
|
|
|
} // namespace Void::Build::Package
|