System: implement FileLock, symlink swap, reflink copy and timestamps on Windows
- FileLock: _wopen + LockFileEx/UnlockFileEx byte-range locks (shared and exclusive, blocking and non-blocking). - atomic_symlink_swap: CreateSymbolicLinkW to a temp name, then MoveFileExW replace (write-through for durable_sync). - reflink_copy_file: staged copy with an FSCTL_DUPLICATE_EXTENTS_TO_FILE block-clone attempt and a streaming private-copy fallback, no-overwrite publish, attribute preservation and optional parent flush. - set_timestamps_nofollow: FILE_WRITE_ATTRIBUTES handle opened with FILE_FLAG_OPEN_REPARSE_POINT and SetFileTime. - OwnedFd now actually closes its descriptor on Windows. The combined filesystem test runs on both platforms now. Verified under Wine 11 (x86_64-w64-mingw32 GCC 16.2): full suite passes (1337 tests, 1326 passed, 11 skipped, 0 failed). Linux System+Testing suite unchanged (477 tests, 474 passed).
This commit is contained in:
1 parent
482a3ea46b
commit
dcfde7f51d
3 files changed
+453
-31
No files matched your search
@@ -108,9 +108,6 @@ Void::Testing::Test remove_path_handles_missing_and_recursive()
|
||||
|
||||
Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Void::Testing::skip("POSIX-only filesystem semantics");
|
||||
#else
|
||||
Void::FileSystem::TempDir tmp{"void_fs_vl010_"};
|
||||
|
||||
// 1. RAII advisory FileLock (shared & exclusive, blocking & try_lock)
|
||||
@@ -148,16 +145,30 @@ Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps()
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::atomic_symlink_swap(link_path, "v1")
|
||||
.has_value());
|
||||
#ifdef _WIN32
|
||||
// MinGW's libstdc++ does not implement read_symlink; a symlink is a
|
||||
// reparse point.
|
||||
const DWORD attrs_v1 = ::GetFileAttributesW(link_path.c_str());
|
||||
Void::Testing::expect(attrs_v1 != INVALID_FILE_ATTRIBUTES &&
|
||||
(attrs_v1 & FILE_ATTRIBUTE_REPARSE_POINT) != 0);
|
||||
#else
|
||||
Void::Testing::expect_eq(
|
||||
std::filesystem::read_symlink(link_path).string(),
|
||||
std::string{"v1"});
|
||||
#endif
|
||||
|
||||
Void::Testing::require(
|
||||
Void::FileSystem::atomic_symlink_swap(link_path, "v2")
|
||||
.has_value());
|
||||
#ifdef _WIN32
|
||||
const DWORD attrs_v2 = ::GetFileAttributesW(link_path.c_str());
|
||||
Void::Testing::expect(attrs_v2 != INVALID_FILE_ATTRIBUTES &&
|
||||
(attrs_v2 & FILE_ATTRIBUTE_REPARSE_POINT) != 0);
|
||||
#else
|
||||
Void::Testing::expect_eq(
|
||||
std::filesystem::read_symlink(link_path).string(),
|
||||
std::string{"v2"});
|
||||
#endif
|
||||
}
|
||||
|
||||
// 3. reflink_copy_file isolates copied file (never hardlinked)
|
||||
@@ -174,6 +185,7 @@ Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps()
|
||||
Void::Testing::expect_eq(
|
||||
Void::FileSystem::read_file(dst).value(), payload);
|
||||
|
||||
#ifndef _WIN32
|
||||
struct stat st_src {};
|
||||
struct stat st_dst {};
|
||||
Void::Testing::require(::lstat(src.c_str(), &st_src) == 0);
|
||||
@@ -181,6 +193,7 @@ Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps()
|
||||
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});
|
||||
#endif
|
||||
|
||||
// overwrite == false must fail cleanly when dst already exists
|
||||
Void::FileSystem::CopyOptions no_overwrite;
|
||||
@@ -214,6 +227,7 @@ Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps()
|
||||
Void::FileSystem::set_canonical_mtime(link, kLinkMtime)
|
||||
.has_value());
|
||||
|
||||
#ifndef _WIN32
|
||||
struct stat st_target {};
|
||||
struct stat st_link {};
|
||||
Void::Testing::require(::lstat(target.c_str(), &st_target) == 0);
|
||||
@@ -222,8 +236,8 @@ Void::Testing::Test filesystem_file_lock_symlink_swap_reflink_and_timestamps()
|
||||
kTargetMtime);
|
||||
Void::Testing::expect_eq(static_cast<std::int64_t>(st_link.st_mtim.tv_sec),
|
||||
kLinkMtime);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
|
||||
Reference in new issue
Block a user