From cf29ecdb6389cff774c33b6521f8a86f7c09d243 Mon Sep 17 00:00:00 2001 From: Richard Hodges Date: Fri, 10 Dec 2021 12:57:37 +0000 Subject: [PATCH] Fix open append mode for file_win32 --- CHANGELOG.md | 1 + include/boost/beast/core/impl/file_win32.ipp | 2 +- test/beast/core/file_test.hpp | 14 +++++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d822023a..9e4f6a61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Fix open append mode for file_win32. * Add tests for file open in append mode. * Fix file open with append/append_existing flag on Windows. diff --git a/include/boost/beast/core/impl/file_win32.ipp b/include/boost/beast/core/impl/file_win32.ipp index 3d0124e6..d7000c5e 100644 --- a/include/boost/beast/core/impl/file_win32.ipp +++ b/include/boost/beast/core/impl/file_win32.ipp @@ -175,7 +175,7 @@ open(char const* path, file_mode mode, error_code& ec) desired_access = boost::winapi::GENERIC_READ_ | boost::winapi::GENERIC_WRITE_; - creation_disposition = boost::winapi::CREATE_ALWAYS_; + creation_disposition = boost::winapi::OPEN_ALWAYS_; flags_and_attributes = 0x08000000; // FILE_FLAG_SEQUENTIAL_SCAN break; diff --git a/test/beast/core/file_test.hpp b/test/beast/core/file_test.hpp index fac2f45b..0d51c6ae 100644 --- a/test/beast/core/file_test.hpp +++ b/test/beast/core/file_test.hpp @@ -88,11 +88,13 @@ test_file() }; auto const create = - [](fs::path const& path) + [](fs::path const& path, std::string const& data = "") { BEAST_EXPECT(! fs::exists(path)); fs::ofstream out(path); BEAST_EXPECT(out.is_open()); + if (data.size()) + out.write(data.c_str(), data.size()); }; auto const remove = @@ -285,10 +287,16 @@ test_file() { File f; error_code ec; - create(path); - BEAST_EXPECT(fs::exists(path)); + create(path, "the cat"); f.open(path, file_mode::append_existing, ec); BEAST_EXPECT(! ec); + static std::string const extra = " sat"; + f.write(extra.c_str(), extra.size(), ec); + BEAST_EXPECT(!ec); + f.close(ec); + BEAST_EXPECT(!ec); + auto s = consume_file(path); + BEAST_EXPECTS(s == "the cat sat", s); } remove(path); }