Skip to content

Commit b46c770

Browse files
committed
Enable Series creation in Append mode
1 parent c776dc4 commit b46c770

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ void JSONIOHandlerImpl::createFile(
102102
}
103103

104104
auto res_pair = getPossiblyExisting(name);
105+
auto fullPathToFile = fullPath(std::get<0>(res_pair));
105106
File shared_name = File(name);
106107
VERIFY_ALWAYS(
107108
!(m_handler->m_backendAccess == Access::READ_WRITE &&
108109
(!std::get<2>(res_pair) ||
109-
auxiliary::file_exists(fullPath(std::get<0>(res_pair))))),
110+
auxiliary::file_exists(fullPathToFile))),
110111
"[JSON] Can only overwrite existing file in CREATE mode.");
111112

112113
if (!std::get<2>(res_pair))
@@ -127,9 +128,12 @@ void JSONIOHandlerImpl::createFile(
127128
associateWithFile(writable, shared_name);
128129
this->m_dirty.emplace(shared_name);
129130

130-
if (m_handler->m_backendAccess != Access::APPEND)
131+
if (m_handler->m_backendAccess != Access::APPEND ||
132+
!auxiliary::file_exists(fullPathToFile))
131133
{
132-
// make sure to overwrite!
134+
// if in create mode: make sure to overwrite
135+
// if in append mode and the file does not exist: create an empty
136+
// dataset
133137
this->m_jsonVals[shared_name] = std::make_shared<nlohmann::json>();
134138
}
135139
// else: the JSON value is not available in m_jsonVals and will be

test/SerialIOTest.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6046,9 +6046,14 @@ void append_mode(
60466046
std::string jsonConfig = "{}")
60476047
{
60486048

6049-
std::string filename = (variableBased ? "../samples/append_variablebased."
6050-
: "../samples/append_groupbased.") +
6049+
std::string filename =
6050+
(variableBased ? "../samples/append/append_variablebased."
6051+
: "../samples/append/append_groupbased.") +
60516052
extension;
6053+
if (auxiliary::directory_exists("../samples/append"))
6054+
{
6055+
auxiliary::remove_directory("../samples/append");
6056+
}
60526057
std::vector<int> data(10, 0);
60536058
auto writeSomeIterations = [&data](
60546059
WriteIterations &&writeIterations,
@@ -6064,7 +6069,7 @@ void append_mode(
60646069
}
60656070
};
60666071
{
6067-
Series write(filename, Access::CREATE, jsonConfig);
6072+
Series write(filename, Access::APPEND, jsonConfig);
60686073
if (variableBased)
60696074
{
60706075
if (write.backend() != "ADIOS2")

0 commit comments

Comments
 (0)