ENH: add support for OFstream atomic file creation (#2631)

- with ATOMIC, an intermediary file is created - eg, (fileAbc~tmp~)
  where all of the output is written to. When the stream goes out of
  scope, this intermediary file is moved/renamed to the actually
  output name - eg, (fileAbc~tmp~) -> (fileAbc).

  This adds some safety if the simulation crashes while writing the
  file, since it will the partial (corrupt) file will be left
  behind as (fileAbc~tmp~) and not as (fileAbc), which means it will
  will be treated as a backup file and not loaded again on restart.

ENH: provided enumeration for APPEND/NON_APPEND

- clearer than using bool (with comments).
  Since append mode is primarily only used by masterOFstream etc
  this change is unlikely to affect user coding.

ENH: use file atomic for ensight file creation

- avoids corrupt (truncated) files being referenced by the ensight
  case file if the simulation crashes while writing the ensight file.
This commit is contained in:
Mark Olesen
2022-11-08 21:01:22 +01:00
parent 9f7cfa9419
commit 5338e56c73
23 changed files with 559 additions and 134 deletions

View File

@ -79,7 +79,7 @@ Foam::ensightFile::ensightFile
IOstreamOption::streamFormat fmt
)
:
OFstream(ensight::FileName(pathname), fmt)
OFstream(IOstreamOption::ATOMIC, ensight::FileName(pathname), fmt)
{
init();
}
@ -92,7 +92,7 @@ Foam::ensightFile::ensightFile
IOstreamOption::streamFormat fmt
)
:
OFstream(path/ensight::FileName(name), fmt)
OFstream(IOstreamOption::ATOMIC, path/ensight::FileName(name), fmt)
{
init();
}