From 9f3556e6c9ccdb5fb0c43434657bead9f89066e2 Mon Sep 17 00:00:00 2001 From: Chuck Atkins <chuck.atkins@kitware.com> Date: Tue, 20 Jun 2017 15:11:01 -0600 Subject: [PATCH] Use kwsys instead of posix for directory creation --- source/adios2/CMakeLists.txt | 1 + source/adios2/helper/adiosSystem.cpp | 46 +++------------------------- thirdparty/KWSys/CMakeLists.txt | 2 ++ 3 files changed, 7 insertions(+), 42 deletions(-) diff --git a/source/adios2/CMakeLists.txt b/source/adios2/CMakeLists.txt index f48e0924e..651b7bc59 100644 --- a/source/adios2/CMakeLists.txt +++ b/source/adios2/CMakeLists.txt @@ -48,6 +48,7 @@ target_include_directories(adios2 $<INSTALL_INTERFACE:include> PRIVATE ${ADIOS2_SOURCE_DIR}/source ) +target_link_libraries(adios2 PRIVATE adios2sys) find_package(Threads REQUIRED) target_link_libraries(adios2 PUBLIC ${CMAKE_THREAD_LIBS_INIT}) diff --git a/source/adios2/helper/adiosSystem.cpp b/source/adios2/helper/adiosSystem.cpp index 24cda3d57..8e0b967c5 100644 --- a/source/adios2/helper/adiosSystem.cpp +++ b/source/adios2/helper/adiosSystem.cpp @@ -9,12 +9,11 @@ */ #include "adiosSystem.h" -#include <sys/stat.h> //stat, mkdir -#include <sys/types.h> //CreateDirectory -#include <unistd.h> //CreateDirectory +#include <ctime> //std::ctime #include <chrono> //system_clock, now -#include <ctime> //std::ctime + +#include <adios2sys/SystemTools.hxx> #include "adios2/ADIOSMPI.h" #include "adios2/ADIOSTypes.h" @@ -25,44 +24,7 @@ namespace adios2 bool CreateDirectory(const std::string &fullPath) noexcept { - auto lf_Mkdir = [](const std::string directory, struct stat &st) -> bool { - if (stat(directory.c_str(), &st) == -1) // doesn't exist - { - mkdir(directory.c_str(), 0777); - if (stat(directory.c_str(), &st) == -1) // doesn't exist - { - return false; - } - } - return true; - }; - - bool directoryExists = false; - auto directoryPosition = fullPath.find("/"); - - if (fullPath[0] == '/' || fullPath[0] == '.') - { // find the second '/' - directoryPosition = fullPath.find("/", directoryPosition + 1); - } - - struct stat st = {0}; - if (directoryPosition == fullPath.npos) // no subdirectories - { - directoryExists = lf_Mkdir(fullPath.c_str(), st); - } - else - { - std::string directory(fullPath.substr(0, directoryPosition)); - lf_Mkdir(directory.c_str(), st); - - while (directoryPosition != fullPath.npos) - { - directoryPosition = fullPath.find("/", directoryPosition + 1); - directory = fullPath.substr(0, directoryPosition); - directoryExists = lf_Mkdir(directory.c_str(), st); - } - } - return directoryExists; + return adios2sys::SystemTools::MakeDirectory(fullPath); } bool IsLittleEndian() noexcept diff --git a/thirdparty/KWSys/CMakeLists.txt b/thirdparty/KWSys/CMakeLists.txt index 6faf39f54..62afcc114 100644 --- a/thirdparty/KWSys/CMakeLists.txt +++ b/thirdparty/KWSys/CMakeLists.txt @@ -1,5 +1,7 @@ set(KWSYS_NAMESPACE adios2sys) set(KWSYS_USE_DynamicLoader ON) +set(KWSYS_USE_RegularExpression ON) +set(KWSYS_USE_SystemTools ON) set(KWSYS_BUILD_SHARED OFF) if(NOT ADIOS2_BUILD_SHARED_LIBS) set(KWSYS_INSTALL_EXPORT_NAME adios2) -- GitLab