From cdaca4d59b833ac55c81fb45273b59dc1f452e6d Mon Sep 17 00:00:00 2001 From: Stephan Schulz <stephan.schulz-x2q@rub.de> Date: Mon, 1 Feb 2021 14:21:30 +0100 Subject: [PATCH] check for correct permissions of VTK output directories --- example/ALL_Staggered.cpp | 1 + example/CMakeLists.txt | 2 ++ include/ALL.hpp | 9 +++++++++ tests/CMakeLists.txt | 3 +++ tests/fortran_error/CMakeLists.txt | 3 +++ 5 files changed, 18 insertions(+) create mode 100644 tests/fortran_error/CMakeLists.txt diff --git a/example/ALL_Staggered.cpp b/example/ALL_Staggered.cpp index 328fb23..5f6e5d6 100644 --- a/example/ALL_Staggered.cpp +++ b/example/ALL_Staggered.cpp @@ -228,6 +228,7 @@ int main(int argc, char** argv) jall->printVTKoutlines(CurrentStep); } catch (ALL::FilesystemErrorException &e) { std::cout << e.what() << std::endl; + std::exit(2); // Maybe also treat this error in some way, e.g. whether the simulation // should abort if no output could be written or not. } diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 12a1e44..029269d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -44,6 +44,7 @@ install(TARGETS read_binary_output add_executable(ALL_Staggered ALL_Staggered.cpp) if(CM_ALL_VTK_OUTPUT) + target_compile_definitions(ALL_Staggered PRIVATE ALL_VTK_OUTPUT_EXAMPLE) target_include_directories(ALL_Staggered PUBLIC ${VTK_INCLUDE_DIRS}) target_link_libraries(ALL_Staggered PUBLIC ${VTK_LIBRARY_DIRS}) endif(CM_ALL_VTK_OUTPUT) @@ -111,6 +112,7 @@ if(CM_ALL_FORTRAN) add_executable(ALL_Staggered_f ALL_Staggered_f.F90) if(CM_ALL_VTK_OUTPUT) + target_compile_definitions(ALL_Staggered_f PRIVATE ALL_VTK_OUTPUT_EXAMPLE) target_include_directories(ALL_Staggered_f PUBLIC ${VTK_INCLUDE_DIRS}) target_link_libraries(ALL_Staggered_f PUBLIC ${VTK_LIBRARY_DIRS}) endif(CM_ALL_VTK_OUTPUT) diff --git a/include/ALL.hpp b/include/ALL.hpp index 2308e0a..52efc82 100644 --- a/include/ALL.hpp +++ b/include/ALL.hpp @@ -827,6 +827,15 @@ private: __FILE__, __func__, __LINE__, "Could not create output directory."); } + // check permission in case directory already existed, but had wrong + // permissions + struct stat attr; + stat(filename, &attr); + if( (attr.st_mode & S_IRWXU) != S_IRWXU) { + throw FilesystemErrorException( + __FILE__, __func__, __LINE__, + "Possibly already existing directory does not have correct permissions (rwx) for user"); + } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 67946b0..68f5bca 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,4 +2,7 @@ add_subdirectory(unit) if(CM_ALL_TESTS_INTEGRATION) add_subdirectory(feature) endif() +if(CM_ALL_FORTRAN) + add_subdirectory(fortran_error) +endif() # vim: sw=4 ts=4 et diff --git a/tests/fortran_error/CMakeLists.txt b/tests/fortran_error/CMakeLists.txt new file mode 100644 index 0000000..bea56d3 --- /dev/null +++ b/tests/fortran_error/CMakeLists.txt @@ -0,0 +1,3 @@ + + +# vim: et sw=4 ts=4 -- GitLab