From 299870c57c6626e32aaac85a03a6d029b5263005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Fri, 13 Dec 2024 18:50:23 +0100 Subject: [PATCH] TOUCH IOTask: Avoid setting files as dirty in non-write modes (#1704) * Bugfix: Consider dirty upon touch() only in write modes * Add error check to avoid writing in read-only mode --- src/IO/ADIOS/ADIOS2IOHandler.cpp | 10 +++++++++- src/IO/JSON/JSONIOHandlerImpl.cpp | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) 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)