- TempDir/TempFile: implement the Windows branch (path-based no-follow cleanup, volume/file-index identity, normalized temp base). - Path: let the staging cleanup delete the temp file while its handle is open (FILE_SHARE_DELETE) and open the parent directory with write access before FlushFileBuffers. - Configuration: read the environment through _environ on Windows. - Tests: binary ofstream for read_file, portable setenv/getpid, skip DirectoryWatcher on Windows, builtin Ed25519 vector, Archive hardening permission assertions guarded. Verified under Wine 11 with x86_64-w64-mingw32 GCC 16.2: Archive 6/6, ArchiveHardening 10/10, Crypto 3/3, Path 9/11 (2 skipped), TempDir 5/5, TempFile 5/5, Sources 7/7, DirectoryWatcher skipped (no backend), Log 12/12. Linux suites unchanged (477 and 787 tests, 0 failures). Refs #65
69 lines
1.8 KiB
C++
69 lines
1.8 KiB
C++
#include <Void/System/TempFile.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <utility>
|
|
|
|
Void::Testing::Test temp_file_creates_under_temp_and_removes()
|
|
{
|
|
std::filesystem::path captured;
|
|
{
|
|
Void::FileSystem::TempFile tmp;
|
|
captured = tmp.path();
|
|
Void::Testing::expect(std::filesystem::is_regular_file(captured));
|
|
// temp_directory_path() keeps a trailing separator on Windows.
|
|
auto normalize = [](std::filesystem::path value) {
|
|
std::string text = value.generic_string();
|
|
while (text.size() > 1 && text.back() == '/') {
|
|
text.pop_back();
|
|
}
|
|
return text;
|
|
};
|
|
Void::Testing::expect(normalize(captured.parent_path()) ==
|
|
normalize(std::filesystem::temp_directory_path()));
|
|
}
|
|
Void::Testing::expect(!std::filesystem::exists(captured));
|
|
}
|
|
|
|
Void::Testing::Test temp_file_honors_extension()
|
|
{
|
|
Void::FileSystem::TempFile tmp{"void_", ".so"};
|
|
Void::Testing::expect_eq(tmp.path().extension().string(),
|
|
std::string{".so"});
|
|
}
|
|
|
|
Void::Testing::Test temp_file_keep_persists()
|
|
{
|
|
std::filesystem::path captured;
|
|
{
|
|
Void::FileSystem::TempFile tmp;
|
|
captured = tmp.keep();
|
|
}
|
|
Void::Testing::expect(std::filesystem::exists(captured));
|
|
std::error_code ec;
|
|
std::filesystem::remove(captured, ec); // manual cleanup
|
|
}
|
|
|
|
Void::Testing::Test temp_file_move_transfers_ownership()
|
|
{
|
|
std::filesystem::path captured;
|
|
{
|
|
Void::FileSystem::TempFile a;
|
|
captured = a.path();
|
|
Void::FileSystem::TempFile b = std::move(a);
|
|
Void::Testing::expect_eq(b.path(), captured);
|
|
Void::Testing::expect(a.path().empty());
|
|
}
|
|
// Removed once (by b); no double-remove crash.
|
|
Void::Testing::expect(!std::filesystem::exists(captured));
|
|
}
|
|
|
|
Void::Testing::Test temp_files_are_unique()
|
|
{
|
|
Void::FileSystem::TempFile a;
|
|
Void::FileSystem::TempFile b;
|
|
Void::Testing::expect(a.path() != b.path());
|
|
}
|