diff --git a/src/RMGRunAction.cc b/src/RMGRunAction.cc index d44a9224..7ee2ba78 100644 --- a/src/RMGRunAction.cc +++ b/src/RMGRunAction.cc @@ -239,8 +239,13 @@ std::pair RMGRunAction::BuildOutputFile() const { // TODO: realpath auto path = fs::path(manager->GetOutputFileName()); - if (fs::exists(path) && !manager->GetOutputOverwriteFiles()) { - RMGLog::Out(RMGLog::fatal, "Output file ", path.string(), " does already exists."); + auto path_for_overwrite = + fs::path(G4Analysis::GetTnFileName(path.string(), path.extension().string())); + if (fs::exists(path_for_overwrite) && !manager->GetOutputOverwriteFiles()) { + RMGLog::Out(RMGLog::error, "Output file ", path_for_overwrite.string(), " does already exists."); + // need to abort here (and not use ::fatal), as Geant4 is not prepared to take exceptions at + // this stage. also, there is no clean way to abort an run before the run started. + std::abort(); } auto ext = path.extension();