diff --git a/src/IO/ADIOS/ADIOS2IOHandler.cpp b/src/IO/ADIOS/ADIOS2IOHandler.cpp index 855958c888..05cf7cd689 100644 --- a/src/IO/ADIOS/ADIOS2IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS2IOHandler.cpp @@ -1520,7 +1520,15 @@ void ADIOS2IOHandlerImpl::touch( Writable *writable, Parameter const &) { auto file = refreshFileFromParent(writable, /* preferParentFile = */ false); - m_dirty.emplace(std::move(file)); + if (access::write(m_handler->m_backendAccess)) + { + m_dirty.emplace(std::move(file)); + } + else if (m_fileData.find(file) == m_fileData.end()) + { + throw error::Internal( + "ADIOS2: Tried activating a file that is not open."); + } } adios2::Mode ADIOS2IOHandlerImpl::adios2AccessMode(std::string const &fullPath) diff --git a/src/IO/JSON/JSONIOHandlerImpl.cpp b/src/IO/JSON/JSONIOHandlerImpl.cpp index 38de34f072..b1046c4602 100644 --- a/src/IO/JSON/JSONIOHandlerImpl.cpp +++ b/src/IO/JSON/JSONIOHandlerImpl.cpp @@ -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" @@ -158,6 +159,11 @@ JSONIOHandlerImpl::~JSONIOHandlerImpl() = default; std::future 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); @@ -1044,7 +1050,15 @@ void JSONIOHandlerImpl::touch( Writable *writable, Parameter const &) { auto file = refreshFileFromParent(writable); - m_dirty.emplace(std::move(file)); + if (access::write(m_handler->m_backendAccess)) + { + m_dirty.emplace(std::move(file)); + } + else if (m_jsonVals.find(file) == m_jsonVals.end()) + { + throw error::Internal( + "ADIOS2: Tried activating a file that is not open."); + } } auto JSONIOHandlerImpl::getFilehandle(File const &fileName, Access access)