@@ -508,32 +508,36 @@ void ADIOS2IOHandlerImpl::checkFile(
508
508
std::string name =
509
509
fullPath (parameters.name + fileSuffix (/* verbose = */ false ));
510
510
511
+ using FileExists = Parameter<Operation::CHECK_FILE>::FileExists;
512
+ *parameters.fileExists = checkFile (name) ? FileExists::Yes : FileExists::No;
513
+ }
514
+
515
+ bool ADIOS2IOHandlerImpl::checkFile (std::string fullFilePath) const
516
+ {
511
517
if (m_engineType == " bp3" )
512
518
{
513
- if (!auxiliary::ends_with (name , " .bp" ))
519
+ if (!auxiliary::ends_with (fullFilePath , " .bp" ))
514
520
{
515
521
/*
516
522
* BP3 will add this ending if not specified
517
523
*/
518
- name += " .bp" ;
524
+ fullFilePath += " .bp" ;
519
525
}
520
526
}
521
527
else if (m_engineType == " sst" )
522
528
{
523
529
/*
524
530
* SST will add this ending indiscriminately
525
531
*/
526
- name += " .sst" ;
532
+ fullFilePath += " .sst" ;
527
533
}
528
-
529
534
char fileExists = false ;
530
- auxiliary::runOnRankZero (m_communicator, [&fileExists, &name ]() {
531
- fileExists =
532
- auxiliary::file_exists (name) || auxiliary:: directory_exists (name );
535
+ auxiliary::runOnRankZero (m_communicator, [&fileExists, &fullFilePath ]() {
536
+ fileExists = auxiliary::file_exists (fullFilePath) ||
537
+ auxiliary::directory_exists (fullFilePath );
533
538
});
534
539
auxiliary::MPI_Bcast_fromRankZero (m_communicator, &fileExists);
535
- using FileExists = Parameter<Operation::CHECK_FILE>::FileExists;
536
- *parameters.fileExists = fileExists ? FileExists::Yes : FileExists::No;
540
+ return fileExists;
537
541
}
538
542
539
543
void ADIOS2IOHandlerImpl::createPath (
@@ -2669,25 +2673,8 @@ namespace detail
2669
2673
* files. So, we first check for file existence and switch to
2670
2674
* create mode if it does not exist.
2671
2675
*/
2672
- {
2673
- try
2674
- {
2675
- adios2::Engine checkExists =
2676
- m_IO.Open (m_file, adios2::Mode::Read);
2677
- if (!checkExists)
2678
- {
2679
- tempMode = adios2::Mode::Write;
2680
- }
2681
- else
2682
- {
2683
- checkExists.Close ();
2684
- }
2685
- }
2686
- catch (...)
2687
- {
2688
- tempMode = adios2::Mode::Write;
2689
- }
2690
- }
2676
+ tempMode = m_impl->checkFile (m_file) ? adios2::Mode::Append
2677
+ : adios2::Mode::Write;
2691
2678
[[fallthrough]];
2692
2679
#endif
2693
2680
case adios2::Mode::Write: {
0 commit comments