Commit f0639090 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Move check to before we read the ICs and sort out issue with the result from dirname()

Also use errno to get the detailed error about the failure
parent 5e2482a0
......@@ -26,6 +26,7 @@
#include "../config.h"
/* Some standard headers. */
#include <errno.h>
#include <fenv.h>
#include <libgen.h>
#include <stdio.h>
......@@ -385,6 +386,16 @@ int main(int argc, char *argv[]) {
MPI_Bcast(params, sizeof(struct swift_params), MPI_BYTE, 0, MPI_COMM_WORLD);
#endif
/* Check that we can write the snapshots by testing if the output
* directory exists and is writable. */
char basename[PARSER_MAX_LINE_SIZE];
parser_get_param_string(params, "Snapshots:basename", basename);
const char *dirp = dirname(basename);
if (access(dirp, W_OK) != 0) {
error("Cannot write snapshots in directory %s (%s)", dirp,
strerror(errno));
}
/* Prepare the domain decomposition scheme */
struct repartition reparttype;
#ifdef WITH_MPI
......@@ -634,21 +645,6 @@ int main(int argc, char *argv[]) {
/* Initialise the particles */
engine_init_particles(&e, flag_entropy_ICs, clean_h_values);
/* Check if output directory exists */
char dir[200];
int test;
/* get output directory */
strcpy(dir, e.snapshotBaseName);
dirname(dir);
/* test if directory is current directory and update name if yes */
test = strchr(e.snapshotBaseName, '/') == NULL;
if (test) strcpy(dir, "./");
/* Check if user has write permission */
test = access(dir, W_OK);
if (-1 == test)
error("Directory %s does not exist or you do not have write permission",
dir);
/* Write the state of the system before starting time integration. */
engine_dump_snapshot(&e);
......
......@@ -157,7 +157,7 @@ struct engine {
double timeFirstSnapshot;
double deltaTimeSnapshot;
integertime_t ti_nextSnapshot;
char snapshotBaseName[200];
char snapshotBaseName[PARSER_MAX_LINE_SIZE];
int snapshotCompression;
struct unit_system *snapshotUnits;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment