diff --git a/cpp/benchmarks/text/subword.cpp b/cpp/benchmarks/text/subword.cpp index 150f578a22a..b8311324f70 100644 --- a/cpp/benchmarks/text/subword.cpp +++ b/cpp/benchmarks/text/subword.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -29,7 +30,7 @@ static std::string create_hash_vocab_file() { - std::string dir_template("/tmp"); + std::string dir_template{std::filesystem::temp_directory_path().string()}; if (const char* env_p = std::getenv("WORKSPACE")) dir_template = env_p; std::string hash_file = dir_template + "/hash_vocab.txt"; // create a fake hashed vocab text file for this test diff --git a/cpp/include/cudf_test/file_utilities.hpp b/cpp/include/cudf_test/file_utilities.hpp index 4df7b6a69c8..d722b836674 100644 --- a/cpp/include/cudf_test/file_utilities.hpp +++ b/cpp/include/cudf_test/file_utilities.hpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -34,17 +35,14 @@ class temp_directory { public: temp_directory(const std::string& base_name) { - std::string dir_template("/tmp"); - if (const char* env_p = std::getenv("WORKSPACE")) dir_template = env_p; + std::string dir_template{std::filesystem::temp_directory_path().string()}; + if (auto env_p = std::getenv("WORKSPACE")) dir_template = env_p; + dir_template += "/" + base_name + ".XXXXXX"; auto const tmpdirptr = mkdtemp(const_cast(dir_template.data())); - if (tmpdirptr == nullptr) CUDF_FAIL("Temporary directory creation failure: " + dir_template); - _path = dir_template + "/"; - } + CUDF_EXPECTS(tmpdirptr != nullptr, "Temporary directory creation failure: " + dir_template); - static int rm_files(const char* pathname, const struct stat* sbuf, int type, struct FTW* ftwb) - { - return std::remove(pathname); + _path = dir_template + "/"; } temp_directory& operator=(temp_directory const&) = delete; @@ -52,11 +50,7 @@ class temp_directory { temp_directory& operator=(temp_directory&&) = default; temp_directory(temp_directory&&) = default; - ~temp_directory() - { - // TODO: should use std::filesystem instead, once C++17 support added - nftw(_path.c_str(), rm_files, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS); - } + ~temp_directory() { std::filesystem::remove_all(std::filesystem::path{_path}); } /** * @brief Returns the path of the temporary directory