From 7e23e02a4a3431b5c6ae9d10fc4f7f8be7510156 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Mon, 5 Feb 2018 11:20:31 +0000
Subject: [PATCH] Make saving previous collection of restart files an option

---
 examples/parameter_example.yml | 1 +
 src/engine.c                   | 3 +++
 src/engine.h                   | 3 +++
 src/restart.c                  | 6 +++---
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml
index 36da7a1e99..046ad0da52 100644
--- a/examples/parameter_example.yml
+++ b/examples/parameter_example.yml
@@ -78,6 +78,7 @@ InitialConditions:
 # Parameters controlling restarts
 Restarts:
   enable:      1        # (Optional) whether to enable dumping restarts at fixed intervals.
+  save:        1        # (Optional) whether to save copies of the previous set of restart files (named .prev)
   onexit:      0        # (Optional) whether to dump restarts on exit (*needs enable*)
   subdir:      restart  # (Optional) name of subdirectory for restart files.
   basename:    swift    # (Optional) prefix used in naming restart files.
diff --git a/src/engine.c b/src/engine.c
index 7967bdf01a..9349aa7e4e 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -5569,6 +5569,9 @@ void engine_config(int restart, struct engine *e,
   /* Whether restarts are enabled. Yes by default. Can be changed on restart. */
   e->restart_dump = parser_get_opt_param_int(params, "Restarts:enable", 1);
 
+  /* Whether to save backup copies of the previous restart files. */
+  e->restart_save = parser_get_opt_param_int(params, "Restarts:save", 1);
+
   /* Whether restarts should be dumped on exit. Not by default. Can be changed
    * on restart. */
   e->restart_onexit = parser_get_opt_param_int(params, "Restarts:onexit", 0);
diff --git a/src/engine.h b/src/engine.h
index 25d82a5705..67ca66c12f 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -296,6 +296,9 @@ struct engine {
   /* Whether to dump restart files. */
   int restart_dump;
 
+  /* Whether to save previous generation of restart files. */
+  int restart_save;
+
   /* Whether to dump restart files after the last step. */
   int restart_onexit;
 
diff --git a/src/restart.c b/src/restart.c
index 0d248adda3..881250fd23 100644
--- a/src/restart.c
+++ b/src/restart.c
@@ -128,8 +128,8 @@ void restart_locate_free(int nfiles, char **files) {
  */
 void restart_write(struct engine *e, const char *filename) {
 
-  /* Backup the existing restart file. XXX configure this. */
-  restart_save_previous(filename);
+  /* Save a backup the existing restart file, if requested. */
+  if (e->restart_save) restart_save_previous(filename);
 
   FILE *stream = fopen(filename, "w");
   if (stream == NULL)
@@ -289,7 +289,7 @@ int restart_stop_now(const char *dir, int cleanup) {
 
 /**
  * @brief check if a file with the given name exists and rename to
- *        <filename>.prev. Used to move old restart files before overwriting.
+ *        {filename}.prev. Used to move old restart files before overwriting.
  *
  *        Does nothing if the file does not exist.
  *
-- 
GitLab