Skip to content

Commit

Permalink
TOUCH IOTask: Avoid setting files as dirty in non-write modes (#1704)
Browse files Browse the repository at this point in the history
* Bugfix: Consider dirty upon touch() only in write modes

* Add error check to avoid writing in read-only mode
  • Loading branch information
franzpoeschel authored Dec 13, 2024
1 parent b8ce8a0 commit c639257
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,15 @@ void ADIOS2IOHandlerImpl::touch(
Writable *writable, Parameter<Operation::TOUCH> 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(
Expand Down
16 changes: 15 additions & 1 deletion 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 Expand Up @@ -1044,7 +1050,15 @@ void JSONIOHandlerImpl::touch(
Writable *writable, Parameter<Operation::TOUCH> 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)
Expand Down

0 comments on commit c639257

Please sign in to comment.