Fix open append mode for file_win32

This commit is contained in:
Richard Hodges
2021-12-10 12:57:37 +00:00
parent 88d5deec0f
commit cf29ecdb63
3 changed files with 13 additions and 4 deletions

View File

@@ -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.

View File

@@ -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;

View File

@@ -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);
}