From f6fa9cdf3eea34ef477da1f5d9450c956cc87914 Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Wed, 14 Mar 2018 15:18:37 -0500 Subject: [PATCH] =?UTF-8?q?#506=20added=20additional=20check=20on=20run=20?= =?UTF-8?q?directory=20to=20prevent=20creation=20as=20defaul=E2=80=A6=20(#?= =?UTF-8?q?566)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added additional check on run directory to prevent creation as default output directory * #506 edited error messages to include strerror --- .../CommandLineArguments/CommandLineArguments.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp b/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp index 053884c6..ac94142d 100644 --- a/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp +++ b/trick_source/sim_services/CommandLineArguments/CommandLineArguments.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "trick/CommandLineArguments.hh" #include "trick/memorymanager_c_intf.h" @@ -163,13 +165,18 @@ int Trick::CommandLineArguments::process_sim_args(int nargs , char **args) { } else { run_dir = "." ; } + /* check existence of run directory */ + if (access(run_dir.c_str(), F_OK) != 0) { + std::cerr << "\nERROR: while accessing input file directory \"" << run_dir << "\" : " << std::strerror(errno) << std::endl ; + exit(1); + } output_dir = run_dir ; for (ii = 2; ii < argc; ii++) { if (!strncmp("-OO", argv[ii], (size_t) 3) || !strncmp("-O", argv[ii], (size_t) 2)) { if (ii == ( argc - 1 )) { - std::cerr << "\nERROR: No directory specified after -O or -OO argument. Exiting!" << std::endl ; + std::cerr << "\nERROR: No directory specified after -O or -OO argument" << std::endl ; exit(1) ; } /* Output data directory */ @@ -182,13 +189,13 @@ int Trick::CommandLineArguments::process_sim_args(int nargs , char **args) { /* Create output directory if necessary. */ if (access(output_dir.c_str(), F_OK) != 0) { if (mkdir(output_dir.c_str(), 0775) == -1) { - std::cerr << "\nERROR: While trying to create dir \"" << output_dir << "\" Exiting!" << std::endl ; + std::cerr << "\nERROR: While trying to create output directory \"" << output_dir << "\" : " << std::strerror(errno) << std::endl ; exit(1) ; } } else { /* check permissions on output directory */ if (access(output_dir.c_str(), (W_OK|X_OK) ) == -1) { - std::cerr << "\nERROR: Unable to write to \"" << output_dir << "\" Exiting!" << std::endl ; + std::cerr << "\nERROR: while writing to output directory \"" << output_dir << "\" : " << std::strerror(errno) << std::endl ; exit(2) ; } }