VoidBuildSystem CI / 1 · Requirements (push) Successful in 6s
VoidBuildSystem CI / 2C · Windows native build (debug) (push) Failing after 1m32s
VoidBuildSystem CI / 2C · Windows native build (sanitizers) (push) Failing after 18s
VoidBuildSystem CI / 2C · Windows native build (relwithdebinfo) (push) Failing after 3m4s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 6m20s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 6m32s
VoidBuildSystem CI / 3C · Windows native test (debug) (push) Failing after 1m45s
VoidBuildSystem CI / 2B · Windows Wine build (sanitizers) (push) Successful in 6m55s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 6m59s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 6m59s
VoidBuildSystem CI / 3C · Windows native test (sanitizers) (push) Failing after 15s
VoidBuildSystem CI / 3C · Windows native test (relwithdebinfo) (push) Failing after 1m47s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m4s
VoidBuildSystem CI / 4B · Windows package (debug) (push) Successful in 1m6s
VoidBuildSystem CI / 4B · Windows package (sanitizers) (push) Successful in 12s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 4m2s
VoidBuildSystem CI / 4B · Windows package (relwithdebinfo) (push) Successful in 1m44s
VoidBuildSystem CI / 3B · Windows Wine test (sanitizers) (push) Successful in 3m16s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 3m21s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m45s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 6m54s
VoidBuildSystem CI / 4A · Linux package (debug) (push) Skipped
VoidBuildSystem CI / 4A · Linux package (relwithdebinfo) (push) Skipped
VoidBuildSystem CI / 4A · Linux package (sanitizers) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 3m42s
Bump VoidLibrary to 482a3ea (Windows target support: qualified Configuration/Crypto/System/Archive, Windows DirectoryWatcher, TempDir/TempFile, process pipes) and port VBS's own host backends: - Toolchain: Windows/macOS host names and architectures without uname. - Platform FileOps: Win32 stat metadata, CreateFileW+LockFileEx file locks (Void FileLock is POSIX-only, Void/Library#66), no-op directory fsync, GetModuleFileNameW executable path, mtime via std::filesystem, and a file-copy fallback for the compdb alias. - ProcessSupervisor: Windows PATH/PATHEXT resolution and no POSIX waitpid reaping (job objects own descendants). - Snapshot: directory listing through std::filesystem on Windows. - Remote cache/registry client/CDash: curl or Winsock-based HTTP on Windows (Void::Net is not qualified there yet). - Daemon: explicit unsupported errors on Windows (named-pipe transport is Track C3); the registry service stays POSIX-only and is excluded from the Windows build. - StateStore/Sbom/Main/Graph: portable stat, time and path handling. Verified: MinGW-w64 GCC 16.2 builds vbs, vbs_describe, vbs_benchmarks and the sdk/core/v1/selfhost test executables; vbs runs under Wine and the SDK suite passes 17/17. The Linux suite stays green (8/8).
121 lines
4.5 KiB
C++
121 lines
4.5 KiB
C++
#pragma once
|
|
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
#include <Void/System/Path.hpp>
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace Void::Build::Platform {
|
|
|
|
enum class LockMode { Shared, Exclusive };
|
|
|
|
// RAII advisory flock lock delegating directly to Void::FileSystem::FileLock (VL-010).
|
|
class FileLock {
|
|
public:
|
|
FileLock() noexcept = default;
|
|
~FileLock() noexcept = default;
|
|
|
|
FileLock(const FileLock &) = delete;
|
|
FileLock &operator=(const FileLock &) = delete;
|
|
FileLock(FileLock &&other) noexcept = default;
|
|
FileLock &operator=(FileLock &&other) noexcept = default;
|
|
|
|
[[nodiscard]] static Void::Result::Result<FileLock, Void::Result::Error>
|
|
acquire(const std::filesystem::path &lock_path, LockMode mode = LockMode::Exclusive,
|
|
bool non_blocking = false);
|
|
|
|
[[nodiscard]] bool valid() const noexcept {
|
|
#if defined(_WIN32)
|
|
return handle_ != nullptr;
|
|
#else
|
|
return lock_.locked();
|
|
#endif
|
|
}
|
|
void release() noexcept {
|
|
#if defined(_WIN32)
|
|
handle_.reset();
|
|
#else
|
|
lock_.unlock();
|
|
#endif
|
|
}
|
|
|
|
private:
|
|
#if defined(_WIN32)
|
|
explicit FileLock(std::shared_ptr<void> handle) noexcept : handle_{std::move(handle)} {}
|
|
// Win32 HANDLE (CreateFileW + LockFileEx) with an unlock/close deleter, because
|
|
// Void::FileSystem::FileLock is POSIX-only (Void/Library issue #66).
|
|
std::shared_ptr<void> handle_;
|
|
#else
|
|
explicit FileLock(Void::FileSystem::FileLock lock) noexcept : lock_{std::move(lock)} {}
|
|
Void::FileSystem::FileLock lock_;
|
|
#endif
|
|
};
|
|
|
|
struct FileMetadata {
|
|
bool exists{false};
|
|
bool is_regular{false};
|
|
bool is_directory{false};
|
|
bool is_symlink{false};
|
|
std::uint64_t dev{0};
|
|
std::uint64_t ino{0};
|
|
std::uint64_t size{0};
|
|
std::uint64_t nlink{0};
|
|
std::uint32_t mode{0};
|
|
std::int64_t mtime_sec{0};
|
|
std::int64_t mtime_nsec{0};
|
|
std::string symlink_target;
|
|
};
|
|
|
|
// lstat wrapper that distinguishes ENOENT (exists=false) from permission/IO errors.
|
|
[[nodiscard]] Void::Result::Result<FileMetadata, Void::Result::Error>
|
|
stat_lstat(const std::filesystem::path &path);
|
|
|
|
// Private isolated file copy delegating to Void::FileSystem::reflink_copy_file (VL-010).
|
|
// NEVER creates hardlinks. Guarantees distinct inode and nlink == 1 on destination.
|
|
[[nodiscard]] Void::Result::Result<bool, Void::Result::Error>
|
|
copy_isolated(const std::filesystem::path &src, const std::filesystem::path &dst,
|
|
std::optional<std::uint32_t> mode_override = std::nullopt);
|
|
|
|
// Canonicalizes mtime/atime via Void::FileSystem::set_canonical_mtime (VL-010).
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
set_canonical_mtime(const std::filesystem::path &path, std::int64_t epoch_seconds);
|
|
|
|
// Durable atomic file replace (wraps Void::FileSystem::replace_file).
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
atomic_write_file(const std::filesystem::path &path, std::string_view content,
|
|
bool durable_sync = true, unsigned mode = 0644);
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
atomic_write_bytes(const std::filesystem::path &path, std::span<const std::byte> bytes,
|
|
bool durable_sync = true, unsigned mode = 0644);
|
|
|
|
// Atomically replaces symlink via Void::FileSystem::atomic_symlink_swap (VL-010).
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
atomic_swap_symlink(const std::filesystem::path &link_path, const std::filesystem::path &target);
|
|
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
fsync_directory(const std::filesystem::path &dir_path);
|
|
|
|
// Validates that `candidate` stays inside `root` (or one of `allowed_external_roots`)
|
|
// without symlink loops or directory traversal escapes.
|
|
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
|
|
resolve_confined_path(const std::filesystem::path &root, const std::filesystem::path &candidate,
|
|
const std::vector<std::filesystem::path> &allowed_external_roots = {});
|
|
|
|
[[nodiscard]] bool path_is_within(const std::filesystem::path &root,
|
|
const std::filesystem::path &path);
|
|
|
|
// Absolute path of the running executable (Linux: /proc/self/exe). Hosts without a supported
|
|
// mechanism return an explicit error instead of a guessed path.
|
|
[[nodiscard]] Void::Result::Result<std::filesystem::path, Void::Result::Error>
|
|
current_executable_path();
|
|
|
|
} // namespace Void::Build::Platform
|