Skip to content

Commit

Permalink
Add error check to avoid writing in read-only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 13, 2024
1 parent e91e0ef commit c97cacf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/IO/JSON/JSONIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "openPMD/Error.hpp"
#include "openPMD/IO/AbstractIOHandler.hpp"
#include "openPMD/IO/AbstractIOHandlerImpl.hpp"
#include "openPMD/IO/Access.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"
#include "openPMD/auxiliary/JSON_internal.hpp"
#include "openPMD/auxiliary/Memory.hpp"
Expand Down Expand Up @@ -158,6 +159,11 @@ JSONIOHandlerImpl::~JSONIOHandlerImpl() = default;
std::future<void> JSONIOHandlerImpl::flush()
{
AbstractIOHandlerImpl::flush();
if (access::readOnly(m_handler->m_backendAccess) && !m_dirty.empty())
{
throw error::Internal(
"JSON backend: Cannot have dirty files in read-only modes.");
}
for (auto const &file : m_dirty)
{
putJsonContents(file, false);
Expand Down

0 comments on commit c97cacf

Please sign in to comment.