feat(system,config,sqlite): implement VL-001, VL-003, VL-010, VL-011
This commit is contained in:
1 parent
adfc8548dc
commit
b50131f52e
14 files changed
+2660
-139
No files matched your search
@@ -96,3 +96,119 @@ Void::Testing::Test remove_path_handles_missing_and_recursive()
|
||||
Void::Testing::expect(r2.has_value());
|
||||
Void::Testing::expect(!std::filesystem::exists(tmp.path() / "a"));
|
||||
}
|
||||
|
||||
Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps()
|
||||
{
|
||||
Void::FileSystem::TempDir tmp{"void_fs_vl010_"};
|
||||
|
||||
// 1. RAII advisory FileLock (shared & exclusive, blocking & try_lock)
|
||||
{
|
||||
const auto lock_path = tmp / "resource.lock";
|
||||
auto ex = Void::FileSystem::FileLock::lock(
|
||||
lock_path, Void::FileSystem::LockMode::Exclusive);
|
||||
Void::Testing::require(ex.has_value());
|
||||
Void::Testing::expect(ex->locked());
|
||||
|
||||
auto contended_ex = Void::FileSystem::FileLock::try_lock(
|
||||
lock_path, Void::FileSystem::LockMode::Exclusive);
|
||||
Void::Testing::require(contended_ex.has_value());
|
||||
Void::Testing::expect(!contended_ex->has_value());
|
||||
|
||||
auto contended_sh = Void::FileSystem::FileLock::try_lock(
|
||||
lock_path, Void::FileSystem::LockMode::Shared);
|
||||
Void::Testing::require(contended_sh.has_value());
|
||||
Void::Testing::expect(!contended_sh->has_value());
|
||||
|
||||
ex->unlock();
|
||||
Void::Testing::expect(!ex->locked());
|
||||
|
||||
auto sh1 = Void::FileSystem::FileLock::try_lock(
|
||||
lock_path, Void::FileSystem::LockMode::Shared);
|
||||
auto sh2 = Void::FileSystem::FileLock::try_lock(
|
||||
lock_path, Void::FileSystem::LockMode::Shared);
|
||||
Void::Testing::require(sh1.has_value() && sh1->has_value());
|
||||
Void::Testing::require(sh2.has_value() && sh2->has_value());
|
||||
}
|
||||
|
||||
// 2. Atomic symlink swap over missing, existing, and dangling links
|
||||
{
|
||||
const auto link_path = tmp / "current";
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::atomic_symlink_swap(link_path, "v1")
|
||||
.has_value());
|
||||
Void::Testing::expect_eq(
|
||||
std::filesystem::read_symlink(link_path).string(),
|
||||
std::string{"v1"});
|
||||
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::atomic_symlink_swap(link_path, "v2")
|
||||
.has_value());
|
||||
Void::Testing::expect_eq(
|
||||
std::filesystem::read_symlink(link_path).string(),
|
||||
std::string{"v2"});
|
||||
}
|
||||
|
||||
// 3. reflink_copy_file isolates copied file (never hardlinked)
|
||||
{
|
||||
const auto src = tmp / "origin.bin";
|
||||
const auto dst = tmp / "cloned.bin";
|
||||
const std::string payload(128ULL * 1024ULL, 'K');
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::write_file(src, payload).has_value());
|
||||
|
||||
auto cp = Void::FileSystem::reflink_copy_file(src, dst);
|
||||
Void::Testing::require(cp.has_value());
|
||||
Void::Testing::expect_eq(cp->bytes, payload.size());
|
||||
Void::Testing::expect_eq(
|
||||
Void::FileSystem::read_file(dst).value(), payload);
|
||||
|
||||
struct stat st_src {};
|
||||
struct stat st_dst {};
|
||||
Void::Testing::require(::lstat(src.c_str(), &st_src) == 0);
|
||||
Void::Testing::require(::lstat(dst.c_str(), &st_dst) == 0);
|
||||
Void::Testing::expect(st_src.st_ino != st_dst.st_ino);
|
||||
Void::Testing::expect_eq(st_src.st_nlink, nlink_t{1});
|
||||
Void::Testing::expect_eq(st_dst.st_nlink, nlink_t{1});
|
||||
|
||||
// overwrite == false must fail cleanly when dst already exists
|
||||
Void::FileSystem::CopyOptions no_overwrite;
|
||||
no_overwrite.overwrite = false;
|
||||
Void::Testing::expect(
|
||||
!Void::FileSystem::reflink_copy_file(src, dst, no_overwrite)
|
||||
.has_value());
|
||||
|
||||
// Mutating dst must never alter src
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::write_file(dst, "mutated").has_value());
|
||||
Void::Testing::expect_eq(
|
||||
Void::FileSystem::read_file(src).value(), payload);
|
||||
}
|
||||
|
||||
// 4. Canonical timestamp setter with AT_SYMLINK_NOFOLLOW
|
||||
{
|
||||
const auto target = tmp / "real.txt";
|
||||
const auto link = tmp / "alias.txt";
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::write_file(target, "data").has_value());
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::atomic_symlink_swap(link, target).has_value());
|
||||
|
||||
constexpr std::int64_t kTargetMtime = 1'700'000'000LL;
|
||||
constexpr std::int64_t kLinkMtime = 1'600'000'123LL;
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::set_canonical_mtime(target, kTargetMtime)
|
||||
.has_value());
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::set_canonical_mtime(link, kLinkMtime)
|
||||
.has_value());
|
||||
|
||||
struct stat st_target {};
|
||||
struct stat st_link {};
|
||||
Void::Testing::require(::lstat(target.c_str(), &st_target) == 0);
|
||||
Void::Testing::require(::lstat(link.c_str(), &st_link) == 0);
|
||||
Void::Testing::expect_eq(static_cast<std::int64_t>(st_target.st_mtim.tv_sec),
|
||||
kTargetMtime);
|
||||
Void::Testing::expect_eq(static_cast<std::int64_t>(st_link.st_mtim.tv_sec),
|
||||
kLinkMtime);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user