Skip to content

Commit

Permalink
fix(Stream): truncate existing files when creating a WriteStream
Browse files Browse the repository at this point in the history
This fixes unexpected behaviour when passing a path to a file which already exists.

Reported and debugged by @Zirael137 on the GMC Discord. Thank you!
  • Loading branch information
lmichaelis committed Jun 5, 2024
1 parent 3919220 commit 1a4c495
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ namespace zenkit {
public:
explicit WriteStream(std::ostream* stream) : _m_stream(stream), _m_own(false) {}
explicit WriteStream(std::filesystem::path const& path)
: _m_stream(new std::ofstream(path, std::ios::binary)), _m_own(true) {}
: _m_stream(new std::ofstream(path, std::ios::binary | std::ios::out | std::ios::trunc)), _m_own(true) {
}

~WriteStream() noexcept override {
if (_m_own) {
Expand Down

0 comments on commit 1a4c495

Please sign in to comment.