diff options
author | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2006-05-11 14:20:34 +0000 |
---|---|---|
committer | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2006-05-11 14:20:34 +0000 |
commit | d74fb47b045f8660182e045779e81244f83710f1 (patch) | |
tree | 551c83f84205624ded4b3ac5b394f4c6ccd39a33 /src | |
parent | 783c8163b39f692cafd93fad715e9040937d7bfc (diff) |
Introduce new boolean parameter IO::require_empty_output_directory
which can be used to test if IO::out_dir points to either a non-existing
or empty directory at simulation startup. If this parameter is set to "yes"
and an already existing IO::out_dir is found to have any contents
(eg. output files from a previous simulation which was using the same output
directory) Cactus will print an appropriate error message and abort,
as opposed to continuing and (potentially by accident) overwriting existing
files.
The default for IO::require_empty_output_directory is "no".
This applies patch http://www.cactuscode.org/old/pipermail/patches/2006-May/000168.html.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@239 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
Diffstat (limited to 'src')
-rw-r--r-- | src/Startup.c | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/Startup.c b/src/Startup.c index 3417117..4f70c4c 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -25,6 +25,9 @@ #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#ifdef HAVE_DIRENT_H +#include <dirent.h> +#endif #include "ioGH.h" #include "ioutil_Utils.h" @@ -218,6 +221,10 @@ static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH) { int i, maxdim, myproc; ioGH *myGH; +#ifdef HAVE_DIRENT_H + DIR *dir; + struct dirent *file; +#endif DECLARE_CCTK_PARAMETERS @@ -284,10 +291,48 @@ static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH) CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Problem creating default output directory '%s'", out_dir); } - else if (i > 0 && CCTK_Equals (verbose, "full")) + else if (i > 0) { - CCTK_VInfo (CCTK_THORNSTRING, - "default output directory '%s' already exists", out_dir); + if (CCTK_Equals (verbose, "full")) + { + CCTK_VInfo (CCTK_THORNSTRING, + "default output directory '%s' already exists", out_dir); + } + if (require_empty_output_directory) + { +#ifdef HAVE_DIRENT_H + i = 0; + dir = opendir (out_dir); + while ((file = readdir (dir)) != NULL) + { + if (strcmp (file->d_name, ".") == 0 || + strcmp (file->d_name, "..") == 0) + { + continue; + } + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "Found file '%s' in already existing output directory '%s'", + file->d_name, out_dir); + i++; + } + closedir (dir); + if (i) + { + CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, + "You have set IO::out_dir = '%s' and " + "IO::require_empty_output_directory = 'yes'. " + "This output directory already exists and is non-empty.", + out_dir); + } +#else + /* No opendir(3) ??? It's probably a Windows box, so just give up ! */ + CCTK_WARN (0, "You cannot use 'IO::require_empty_output_directory = " + "\"yes\"' on this architecture because it doesn't provide " + "opendir(3) to browse the IO::out_dir directory.\n" + "Please use 'IO::require_empty_output_directories = " + "\"no\"' instead !"); +#endif + } } i = IOUtil_CreateDirectory (GH, checkpoint_dir, ! CCTK_Equals (out_mode, "onefile"), |